1 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
問題是我在 gridview 中有一個(gè)鏈接按鈕,它導(dǎo)致頁面無法正確呈現(xiàn)。
解決方案很簡(jiǎn)單,我只是刪除了鏈接按鈕認(rèn)為我確實(shí)不需要它們的列。
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;一開始的代碼行剛剛解決了我的整個(gè)問題。
- 1 回答
- 0 關(guān)注
- 232 瀏覽
添加回答
舉報(bào)