62,073
社区成员
发帖
与我相关
我的任务
分享
private void Export(string FileType, string FileName)
{
GridView gv= new GridView();
DataTable dt = NewMethod();
this.gv.DataSource = dt;
this.gv.DataBind();
Response.Charset = "GB2312";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("name","hao");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gv.RenderControl(hw);//这里如何换成dataTable
Response.Write(NoHTML(tw.ToString()));
Response.End();
}
DataTable dt = new DataTable();
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
dt.Columns.Add("你需要的列");
//循环遍历 添加
for (int i = 0; i < 给出条件; i++)
{
DataRow drow = dtContent.NewRow();
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
drow["你上面填写的列"] = 赋值;
dtContent.Rows.Add(drow);
}