ASP.NET的web页面gridview导出数据到EXCEL中的问题
我设置的GRIDVIEW一页显示10条数据,前面能成功的导出数据,到最后一页就失败了。我实验了几次,发现是因为最后一页的数据没满10条, 满了就能导出,各位哥哥姐姐帮忙看看,代码如下:
Response.Clear();
Response.BufferOutput = false;
//设定输出的字符集
Response.Charset = "UTF-8";
//假定导出的文件名为FileName.xls
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
//设置导出文件的格式
Response.ContentType = "application/ms-excel";
//关闭ViewState
EnableViewState = false;
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
GridView1.RenderControl(textWriter);
//把HTML写回浏览器
Response.Write(stringWriter.ToString());
Response.End();
网上的大概也都这样,跪求速解,在线等 昂
------解决方案--------------------
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=AJ_JC.xls");
Response.Charset = "big5";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gvData.AllowPaging = false;
gvData.AllowSorting = false;
BindGridView();
gvData.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();