日期:2014-05-18 浏览次数:20426 次
// GridView1.AllowPaging = false;//取消分页,使GridView显示全部数据. // GridView1.DataBind();//重新绑定.如果不注释这两行,导不出数据,如果注释了这两行,连分页都导出来了, //只能导出一个页面的数据 Response.Clear(); Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "attachment;filename= " + Server.UrlEncode("导出.xls")); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件. this.EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); System.IO.StringWriter stringWrite = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); GridView1.AllowPaging = true; GridView1.DataBind();//重新绑定.