Showing posts with label DataGrid Export to excel file. Show all posts
Showing posts with label DataGrid Export to excel file. Show all posts

Wednesday, October 6, 2010

DataGrid Export to excel file

private void ExportGridToExcel(DataGrid grdGridView, string fileName)
{
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
grdGridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}