GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Microsoft  >  DataGrid

 Print  |  
Question:  Export Data Grid content to Excel File

Answer: 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


October 10, 2007 13:11:10 #1
 Praveen   Member Since: Visitor    Total Comments: N/A 

RE: Export Data Grid content to Excel File
 

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();

     

 

Back To Question