DataGrid2
1、DataGrid的button属性设置
CommandName="ToEdit":
对其中的button按钮进行选择:
CommandArgument='<%#Eval("ID") %>':
可以在后台的DataGrid1_ItemCommand1中获取当前按下的button按钮所在行的ID:
string keyId = e.CommandArgument.ToString();
也可以直接在DataGrid属性里配置ID:
DataKeyField="ID":
string keyId = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
2、DataGrid中的button,实现导出word文档
如:
if (e.CommandName.ToLower() == "toword") //导出word
{
//导出word
string ID = e.CommandArgument.ToString();
object missing = System.Reflection.Missing.Value;
string FileName = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath);
//string aa = ;
string TemplateFile = FileName + @"Template\文件名字.doc";//带有格式的空的“文件名字.doc”文档
FileName += @"FckUploadfile\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
File.Copy(TemplateFile, FileName);
FileInfo fi = new FileInfo(FileName);
//判断文件属性是否只读?是则修改为一般属性再保存
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
fi.Attributes = FileAttributes.Normal;
}
Microsoft.Office.Interop.Word.Application App = new Microsoft.Office.Interop.Word.Application();
try
{
object Obj_FileName = FileName;
object Visible = false;
object ReadOnly = false;
Microsoft.Office.Interop.Word.Document Doc = App.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
Doc.Activate();
// Get the data and fill the data( PersonName ,PersonResume) to the appoint BookMark
DataRow row = AccountRule.导出试用期考核表信息获取(ID).Rows[0];
object BookMarkName = "姓名";
object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["姓名"].ToString());
BookMarkName = "性别";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["姓名"].ToString());
BookMarkName = "出生年月";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["出生年月"].ToString());
BookMarkName = "政治面貌";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["政治面貌"].ToString());
BookMarkName = "单位";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["单位"].ToString());
BookMarkName = "从事工作";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["从事工作"].ToString());
BookMarkName = "学历学位";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["学历"].ToString() + "\r\n" + row["学位"].ToString());
Doc.ActiveWindow.Selection.MoveDown(Microsoft.Office.Interop.Word.WdUnits.wdLine, 6);
BookMarkName = "试用期起止时间";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["试用期起止时间"].ToString());
BookMarkName = "个人总结";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(Convert.IsDBNull(row["个人总结"]) ? string.Empty : row["个人总结"].ToString());
File.SetAttributes(FileName, FileAttributes.Normal);
Doc.Save();
// Save the File and change the File as stream
object IsSave = true;
Doc.Close(ref IsSave, ref missing, ref missing);
Get(FileName);
}
finally
{
App.Quit(ref missing, ref missing, ref missing);
}
//string url = Request.ApplicationPath + @"/qgy/dybg_File.aspx?KeyId=" + keyId;
//Response.Write("<script>window.open('" + url + "','','target=_blank,scrollbars=yes,top=100,left=200,width=600,height=300,scrolling=1');</script>");
}
}
public void Get(string fileName)
{
string paths = Request.MapPath("../FckUploadfile");
string file = Path.Combine(paths, fileName);
FileInfo fi = new FileInfo(file);
if (fi.Exists == true)
{
// const long ChunkSize = 1024;
// byte[] buffer = new byte[ChunkSize];
//Response.Clear();
FileStream istream = File.OpenRead(file);
try
{
byte[] buffer = new byte[istream.Length];
istream.Read(buffer, 0, buffer.Length);
istream.Seek(0, SeekOrigin.Begin);
Response.BinaryWrite(buffer);
//long Data = istream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(file.Substring(file.LastIndexOf("\\") + 1)));
}
finally
{
}
}
}
DataGrid2的更多相关文章
- Struts2 easy UI插件
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- Easy UI常用插件使用
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- Struts2中的EasyUI
Struts2中的EasyUI 一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tre ...
- miniui中常用的状态显示方式
1.查询sys_code表得到对应的状态 考生状态:<input class="mini-combobox" style="" textField=&qu ...
- java_easyui体系之DataGrid(4)[转]
一:简介 在前面DataGrid(3)的基础上添加后台的实现.本来是想只搭建前台页面的.后台不写.现在觉得还是都实现好点.从真实情况出发.后台用的ssh. 1. 新增冻结列功能. 2. 实现界面的添加 ...
- java_easyui体系之DataGrid(3)[转]
一:简介 在2的基础上实现增删改.增.改都是通过行编辑来实现的.具体业务逻辑: 1. 增加一条记录的时候: a) 在datagrid表格最前端增加一行(当然也可在指定位置增加.)增加的行的字段必须与要 ...
- java_easyui体系之DataGrid(2)[转]
一:简介 在1的基础上添加layout组件.实现通过条件动态的从后台查询数据到前台展示.使用的方式是将查询单独作为一个layout中的一个面板. 二:关键之处 1.效果图: 2.左侧的折叠组件: 折叠 ...
- csharp: Data binding in WPF DataGrid control
<Window x:Class="WpfProjectDemo.MainWindow" xmlns="http://schemas.microsoft.com/wi ...
- JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
需求如下 现有数据列三列 Name,Age,CreateDate 数据 张三,18,2000-12-09 :12:34:56 李四,28,2000-12-09 :12:34:56 王麻子,38,200 ...
随机推荐
- 堆排序-C语言实现
堆排序 堆排序是利用堆的性质进行的一种选择排序.下面先讨论一下堆. 1.堆 堆实际上是一棵完全二叉树,其任何一非叶节点满足性质: Key[i]<=key[2i+1]&&Key[i ...
- NServiceBus
官方网站:http://docs.particular.net/nservicebus/ NServiceBus 是一个用于构建企业级 .NET系统的开源通讯框架.它在消息发布/订阅支持.工 ...
- 在asp.net mvc中将checkbox传到后台时总是true的解决方法
我今天在做同城交友网站(www.niyeuwo.com)时发现,不管checkbox是否选 中,传到Controller时总是true,后来在查网上查了资料才知道,原来是jQuery在传值时写错了. ...
- 关于QStringRef
QString 为字符串操作提供了各种成员比如mid().left().right().它们都创建会一个新的字符串,因此有一个对在已存在QString的malloc和深拷贝. 与此相反,QStri ...
- Java_Shell多线程
#!/bin/bash source ~/.bashrc fun(){ echo "fun is begin.timeNum:$timeNum" local timeNum=$ s ...
- 架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层
1.概述 前两遍文章中,我们一直在说后文要介绍Nginx + Keepalived的搭建方式.这篇文章开始,我们就来兑现前文的承诺,后续的两篇文章我们将介绍Nginx + Keepalived和 LV ...
- Java SE ---控制流程:break与continue语句
在java中,可以使用break和continue语句控制循环. 1. break语句:用于终止循环,就是跳出当前循环,执行循环后面的代码. . 2. continue语句:用于跳出当 ...
- remove all .git files and directories use one command
find . -type d -name ".git" | xargs rm -rf
- iOS - UI - UISlider
6.UISlider //滑块 设置高度 UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 100, CGRec ...
- extjs 简单入门
中文网站:http://extjs.org.cn/ 英文网站:http://www.sencha.com/products/extjs/ 1.简介 extJS是一种主要用于创建前端用户界面,是一个基本 ...