i want to download data of datatable in excel. in VS 2005
i tried many method but its no use now i am using following approach.
public void ExportToExcel(DataTable dt)
{
if (dt.Rows.Count > 0)
{
Response.Clear();
string filename = "Breakup wise Stock Summary.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
dgGrid.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
but getting error.
sys.webforms.PageRequestManagerParsererrorException: The message recieved from the server could not be parsed. Common cause for this error are when the responce is modified by calls to Response.Write(),response filter,HttpModules, or server trace is enable.
Detail:Error parsing near