如何在没有包含控件的列的情况下将gridview的所有页面导出到excel? [英] How to export all pages of gridview to excel without columns containing controls?
本文介绍了如何在没有包含控件的列的情况下将gridview的所有页面导出到excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview,它有2列,是一个下拉列表和上传控件。我试图将gridview导出到excel并且代码可以工作,但它只能导出当前视图而不是所有页面。当我尝试导出所有页面时,数据绑定失败并且代码崩溃。如果您知道如何使用或不使用包含控件的列将所有页面导出到excel / csv,请提供帮助。谢谢! Amilah
这是我的代码:
I have a gridview that has 2 columns that are a dropdownlist and upload control. I am trying to export the gridview to excel and the code works but it only works to export the current view not all the pages. When I try to export all pages the data binding fails and code crashes. Please help if you know a way of getting all the pages exported to excel/csv with or without the columns containing controls. Thank you! Amilah
Here is my code:
protected void ExportBtn_Click(object sender, ImageClickEventArgs e)
{
gv.Columns[7].Visible = false;
gv.Columns[8].Visible = false;
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=Documents.xls");
Response.ContentType = "application/excel";
gv.AllowPaging = false;
gv.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Response.Charset = String.Empty;
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
推荐答案
谢谢!我通过复制gridview而没有麻烦列并导出它找到了一个解决方法。
Thank you! I found a work around by duplicating the gridview without the trouble columns and exporting it.
这篇关于如何在没有包含控件的列的情况下将gridview的所有页面导出到excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文