【发布时间】:2016-06-23 11:39:07
【问题描述】:
这里我用 gridview 数据创建 excel 文件,代码如下
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
它工作正常,但是如果我将 gridview 属性设置为 AllowPaging="true",则 excel 文件仅包含分页 1 数据,我如何将所有数据从 gridview 导出到 excel。
【问题讨论】:
-
你把这个allowpaging保存在哪里?