我在将所有数据导出到 Excel 文件时遇到问题。我只设法从 gridview 的第一页导出数据。我可以知道导出数据(包括其他页面中的数据)的正确方法吗?谢谢一堆。
protected void bn_export_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gv_getGameDetails.AllowPaging = false;
//Change the Header Row back to white color
gv_getGameDetails.HeaderRow.Style.Add("background-color", "#FFFFFF");
gv_getGameDetails.HeaderRow.Cells[0].Style.Add("background-color", " #262626");
gv_getGameDetails.HeaderRow.Cells[1].Style.Add("background-color", " #262626");
gv_getGameDetails.HeaderRow.Cells[2].Style.Add("background-color", " #262626");
gv_getGameDetails.HeaderRow.Cells[3].Style.Add("background-color", " #262626");
this.RemoveControls(gv_getGameDetails);
gv_getGameDetails.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();