Datagrid to Excel

M

monalisa

I have a Datagrid in ASP.NET , Witch contains employee info and a
Dropdownlist and a calendar control.
For performance issue, the user wanted to fill this form in Excel, so I need
to export the Data to Excel file to be (offline), and create the drop down
list dynamically into the excel.
How I can do it , and if there is another suggestion of doing this
(infoPath)
 
M

Mark Rae


This works really well, and there are loads of similar examples all over the
Internet.

I'm using the following code:

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition",
"attachment;filename=c:\\valuations.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
this.EnableViewState = false;
System.IO.StringWriter objSW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter objHTMLTW = new HtmlTextWriter(objSW);
tblResults.RenderControl(objHTMLTW);
Response.Write(objSW.ToString());
Response.End();

That's fine, except that it displays the data in the same browser window.

Is there an easy way to actually open up Excel itself rather than merely
displaying the Excel data in the browser? Even opening up another browser
window would be better...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top