zoukankan      html  css  js  c++  java
  • 从GridView导出到Excel时报错:类型GridView的控件GridView1必须放置在具有runat=server的窗体标记内

     

    解决以上问题的办法很简单,只需要在后台代码文件中添加:

     

    public override void VerifyRenderingInServerForm(Control control)
        {

        }

    附: 导出代码:

                    Response.ClearContent();
                    Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
                    HttpContext.Current.Response.Charset = "utf-8";
                    Response.ContentType = "application/excel";

                    StringWriter sw = new StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);

                    GridView1.RenderControl(htw);
                    Response.Write(sw.ToString());
                    Response.End();


     

     

  • 相关阅读:
    vue生命周期总结
    Generator的基本用法
    React context基本用法
    盗链
    Linux 黑白界面显示
    nginx 反向代理Apache
    apache+php windows下配置
    正则表达式匹配空行
    列表页条目不刷新删除
    linux终端自定义设置
  • 原文地址:https://www.cnblogs.com/lgzslf/p/1674664.html
Copyright © 2011-2022 走看看