解决以上问题的办法很简单,只需要在后台代码文件中添加:
public override void VerifyRenderingInServerForm(Control control)
{
}
附: 导出代码:
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
HttpContext.Current.Response.Charset = "utf-8";
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();