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 关注
- 159 浏览
添加回答
举报