Monday, July 12, 2010

Export GridView Data into Excel in C# .Net

Export GridView Data into Excel in C# .Net

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);//DataGrid Name
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

1 comment: