使用导出datagrid到excel,使用下面语句:
public void savetoexcel_Click(object sender, System.EventArgs e)
{
DataGridBind(); //捆绑数据库
Response.Clear();
Response.Buffer= true;
Response.Charset="gb2312";
string Date=DateTime.Now.ToString("yyyy-MM-dd"
;
string filename="单位填报表"+Date;
Response.AddHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(filename)+".xls"
;
Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8"
;
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
为什么转换的只是DataGrid1的当前页,而不是所有页???
如果能够实现所有页的转换,怎么修改呢??谢谢了!!!!