| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 796 人关注过本帖
标题:以下的代码在运行时出现错误:只能在执行 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
快速回复:以下的代码在运行时出现错误:只能在执行 Render() 的过程中调用 ...
数据加载中...
 
   



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

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