1 回答

TA貢獻1853條經驗 獲得超18個贊
問題是我在 gridview 中有一個鏈接按鈕,它導致頁面無法正確呈現。
解決方案很簡單,我只是刪除了鏈接按鈕認為我確實不需要它們的列。
public void ExportToXLS(GridView gv)
{
GV.Columns[4].Visible = false;
GV.Columns[5].Visible = false;
gv.AllowPaging = false;
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=GridView.xls");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView gvExp = new GridView();
gvExp = gv;
gvExp.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
}
GV.Columns[ ].Visible = false;一開始的代碼行剛剛解決了我的整個問題。
- 1 回答
- 0 關注
- 207 瀏覽
添加回答
舉報