<form id="form1" runat="server"> <asp:DataGrid id="DataGrid1" runat="server" /> </form>also this.DataGrid1.RenderControl(hw); ====> form1.DataGrid1.RenderControl(hw); if you have other stuffs in <form>, you might need to remove those stuffs from tw.ToString()
<asp:DataGrid id="DataGrid1" runat="server" />
</form>also
this.DataGrid1.RenderControl(hw);
====>
form1.DataGrid1.RenderControl(hw); if you have other stuffs in <form>, you might need to remove those stuffs from tw.ToString()
====>
this.form1.RenderControl(hw);
怎么去掉这列呢?
另只要DataGrid1中有控件就不行,
现将解决办法写出来如果谁有更好的请告诉我DataGrid DataGrid2=new DataGrid();
DataSet dataSet1=(DataSet)Cache["Sort"];//此处是数据源
DataView sortView1=new DataView(dataSet1.Tables["yybb"]);
DataGrid2.DataSource=sortView1;
DataGrid2.DataBind();
//下面将DataGrid2输出到Excel文件
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=exportfilename.xls");
Response.Charset = "utf-8";
Response.ContentEncoding=System.Text.Encoding.Default;
Response.ContentType = "application/vnd.ms-excel";
//Response.Charset = "";
this.EnableViewState= false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
DataGrid2.RenderControl(hw);
Response.Write(tw);
Response.End();