gpt4 book ai didi

c# - 将 GridView 导出到 XLS --- 分页问题

转载 作者:行者123 更新时间:2023-12-04 06:00:53 25 4
gpt4 key购买 nike

我有一个 GridView,我打算将它导出到 .xls 文件中。在此 GridView 中启用了分页。我目前使用的代码只能导出gridview的第一页。

   Response.Clear();
Response.Buffer = true;

Response.AddHeader("content-disposition","attachment;filename=DataTable.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";

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

//As you notice, below I tried to disable the paging yet it's unsuccessful
//FYI I am able to really prevent first column, header row, and footer row to
//be exported through this

gvGridView.Columns[0].Visible = false;
gvGridView.HeaderRow.Visible = false;
gvGridView.FooterRow.Visible = false;
gvGridView.AllowPaging = false;

for (int i = 0; i < gvGridView.Rows.Count; i++)
{
gvGridView.Rows[i].Attributes.Add("class", "textmode");
}
gvGridView.RenderControl(hw);

string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

我注意到以前有人问过这个问题,但没有正确答案。

任何帮助表示赞赏。

谢谢

最佳答案

你应该重新绑定(bind)你的GridView在您指定 gvGridView.AllowPaging = false; 之后,然后导出。否则 .RenderControl(hw);只会渲染当前选择的GridView页。

关于c# - 将 GridView 导出到 XLS --- 分页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8908363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com