cymxiao

博客园 首页 新随笔 联系 订阅 管理

  GridView导出函数内容如下  

 string attachment = "attachment; filename=Contacts.xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

并且重写了下面方法,

   public override void VerifyRenderingInServerForm(Control control)
        {
        }

 

页面在点击Export按钮后任然没有反应。

本质原因在于GridView控件在Asp.Net的UpdatePanel中,解决方法就是把GridView移出到UpdatePanel之外。

posted on 2013-11-27 21:49  萧雨  阅读(238)  评论(0编辑  收藏  举报