导读: <summary> 导出全部数据 < summary> <param name="FileType">< param> <param nam...
// <summary>
/// 导出全部数据
/// </summary>
/// <param name="FileType"></param>
/// <param name="FileName"></param>
protected void Button6_Click(object sender, EventArgs e)
{
GridView1.AllowPaging = false; //清除分页
GridView1.AllowSorting = false; //清除排序
GetDataALL (); //你绑定gridview1数据源的那个函数。
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=AllData.xls"); //.xls的文件名可修改
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel"; //设置输出文件类型为excel文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
GridView1.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
GridView1.AllowSorting = true; //恢复分页 GridView1.AllowPaging = true; //恢复排序
GetDataALL(); //再次绑定 }
}