我想将gridview导出为excel。为此,我做了以下编码
Response.Clear();
Response.ContentType = "application/ms-excel";
Response.Charset = "";
Page.EnableViewState = false;
Response.AddHeader("Content-Disposition", "inline;filename=report.xls");
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
首先我得到以下错误 无法评估表达式,因为代码已优化或本机框架位于调用堆栈之上
所以在我的页面中我添加了
EnableEventValidation="true"
不,我收到以下错误 RegisterForEventValidation只能在render()
期间调用如何解决问题?
答案 0 :(得分:0)
我已经解决了这个问题。我创建了一个新页面并编写了代码。它workibg