雪地裸体跪求:excel导出的不是GridView的内容而是整个页面?
public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
{}
protected void btExport_Click(object sender, EventArgs e)
{
gvCheckIn_Inf.AllowPaging = false;
gvCheckIn_Inf.DataSource = (DataTable)Session[PageID + "Result_Ds "];
gvCheckIn_Inf.DataBind();
//导出按钮事件,将GridView中的数据导出到Excel中
Response.Clear();
Response.Buffer = true;
Response.Charset = "UTF-8 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=FileName.xls ");
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "UTF-8 ");
//设置输出流为简体中文
Response.ContentType = "application/ms-excel ";
//设置输出文件类型为excel文件。
gvCheckIn_Inf.Page.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "ZH-CN ", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gvCheckIn_Inf.RenderControl(oHtmlTextWriter);