asp.net Gridview导出excel出错
这是我的代码protected void Button1_Click(object sender, EventArgs e)
{
ExcelOut(this.GridView1);
}
public void ExcelOut(GridView gv)
{
if (gv.Rows.Count > 0)
{
Response.Clear();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("_yyyyMMdd_HHmmss") + ".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
}
else
{
Response.Write("没有数据");
}
}
但是出现这样的错误,不知道是哪出错了