首页 >> 甄选问答 >

gridview导出excel的方法(gridview导出excel)

2024-05-30 03:48:11

问题描述:

gridview导出excel的方法(gridview导出excel),求大佬施舍一个解决方案,感激不尽!

最佳答案

推荐答案

2024-05-30 03:48:11

大家好,我是小跳,我来为大家解答以上问题。gridview导出excel的方法,gridview导出excel很多人还不知道,现在让我们一起来看看吧!

1、

1、现在,GridView中已经绑定了数据,接下来的任务就是导出到Excel。下面是button事件中的代码

2、Response.ClearContent();

3、Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");

4、Response.ContentType = "application/excel";

5、StringWriter sw = new StringWriter();

6、HtmlTextWriter htw = new HtmlTextWriter(sw);

7、gvUsers.RenderControl(htw);

8、Response.Write(sw.ToString());

9、Response.End();

10、并且还需要override一下VerifyRenderingInServerForm方法(这一点非常重要,否则在点击按钮后会报错,译者注),代码如下:

11、public override void VerifyRenderingInServerForm(Control control)

12、{

13、}

本文到此讲解完毕了,希望对大家有帮助。

  免责声明:本答案或内容为用户上传,不代表本网观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。 如遇侵权请及时联系本站删除。

 
分享:
最新文章