GridViewl导出excel,分页的内容全部显示
现在导出只显示当前页的部分,怎样让GridView的内容全部导出到excelprotectedvoidButton4_Click(objectsender,EventAr...
现在导出只显示当前页的部分,怎样让GridView的内容全部导出到excel
protected void Button4_Click(object sender, EventArgs e)
{
string FileName = "标题 " + DateTime.Now + ".xls";
Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.UTF8;//System.Text
//如果设置GB2312会出现乱码
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.AddHeader("content-type", "application / ms - excel");//设置输出文件的类型
//或Response.ContentType = FileType;
//定义一个输出流
StringWriter tw = new StringWriter();//System.IO
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView2.RenderControl(hw);//gridview绑定
Response.Write(tw.ToString());
Response.End();
} 展开
protected void Button4_Click(object sender, EventArgs e)
{
string FileName = "标题 " + DateTime.Now + ".xls";
Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.UTF8;//System.Text
//如果设置GB2312会出现乱码
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.AddHeader("content-type", "application / ms - excel");//设置输出文件的类型
//或Response.ContentType = FileType;
//定义一个输出流
StringWriter tw = new StringWriter();//System.IO
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView2.RenderControl(hw);//gridview绑定
Response.Write(tw.ToString());
Response.End();
} 展开
2个回答
展开全部
建一个隐藏的GridView,数据源和字段设置与网页显示的相同,只是不用分页,导出Excel时用隐藏的GridView做数据源即可
追问
额,也是个办法,难道用分页就不能全读取么- -!
追答
页数只是一个链接,在服务器缓存中没有这些数据,所以也无法直接读取
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询