标题:以下的代码在运行时出现错误:只能在执行 Render() 的过程中调用 Reg ...
取消只看楼主
水晶心
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2010-7-27
结帖率:80%
已结贴  问题点数:20 回复次数:0 
以下的代码在运行时出现错误:只能在执行 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(); //删除不用


搜索更多相关主题的帖子: Render 代码 运行 
2010-08-30 11:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-317174-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057922 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved