A
ad
I use the codes below to render a Gridview to Excel.
But it fail with
RegisterForEventValidation can just be call in Render()
But if myGrid is a DataGrid, it run well.
How can I render a GridView to Excel?
----------------------------------------------------------------------------------------
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
But it fail with
RegisterForEventValidation can just be call in Render()
But if myGrid is a DataGrid, it run well.
How can I render a GridView to Excel?
----------------------------------------------------------------------------------------
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();