Exporting Datagrid

see07

Well-known member
Joined
Apr 16, 2004
Messages
78
Location
Mexico City
I have a web form in which I have a datagrid, I need to export this data to a Microsoft Excel sheet.
Does anybody know how to achieve it?
I
 
Finnaly I found a way to do it:

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());
Response.End();

But Id like to avoid system ask user if desires open or save this file, instead would open excel sheet as another window and when user saves the file it be saved as an excel file.

Does somebody knows how achieve this?

Ill appreciate it very much.
A.L.
 
Back
Top