gridview导出excel,内容为空的。
//Gridview中的内容导出到Excel
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
public void BtnExport_Click(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.ContentType = "application/ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
this.GridView1.AllowPaging = false;
this.getData();
this.GridView1.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
this.getData();
}
gridview导出excel,内容为空的。
请大家解答,谢谢。