以下的代码在运行时出现错误:只能在执行 Render() 的过程中调用 RegisterForEventValidation ,如何解决啊?
protected void Button4_Click(object sender, EventArgs e)//导出Excel{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=wasteBook" + DateTime.Now.Date.ToString("yyyyMMdd") + ".xls");
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
oStringWriter = new ();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
// turn off paging
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.RenderControl(htw);
string strHtml = sw.ToString().Trim();
Response.Output.Write(strHtml);
Response.Flush();
Response.End();
// turn the paging on again
// GridView1.AllowPaging = true; //删除不用
// GridView1.DataBind(); //删除不用