这是什么错误?
这是一段将GridView中的记录导出到EXCEL的代码。 protected void PrintV_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "车辆报表.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);“这句怎么有错误?只能在执行 Render() 的过程中调用 RegisterForEventValidation;”
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
运行时出现的错误是:
用户代码未处理 System.InvalidOperationException
GridView1.RenderControl(hw);“这句有错误说::只能在执行 Render() 的过程中调用 RegisterForEventValidation;”
初学,对于如何解决GridView导出到EXCEL的问题很烦恼!
请帮我详细解答一下!