GridView导出函数内容如下
string attachment = "attachment; filename=Contacts.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
并且重写了下面方法,
public override void VerifyRenderingInServerForm(Control control)
{
}
页面在点击Export按钮后任然没有反应。
本质原因在于GridView控件在Asp.Net的UpdatePanel中,解决方法就是把GridView移出到UpdatePanel之外。