0
我有一個問題,將我所有的數據導出到excel文件。我只設法從gridview的第一頁導出數據。我可否知道導出數據的正確方法,包括其他頁面中的數據?謝謝一堆。無法將多頁gridview數據導出爲excel
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();