Export Data Grid content to Excel File

How to get the content of Datagrid into excel format?
I want to use this feature in Windows Application and C#, Visual Studio .NET 2003

Questions by sekaranpg   answers by sekaranpg

Showing Answers 1 - 9 of 9 Answers

Praveen

  • Oct 26th, 2007
 

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=ReviewDesignation.xls");//This
lets you always open the Excel window when exporting whether you click on open
or save.
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new
System.IO.StringWriter();System.Web.UI.HtmlTextWriter oHtmlTextWriter =
new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(dGrid);
dGrid.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions