Datagrid -> Excel?

R

Rob Petersen

Can anyone recommend a good, reliable solution or 3rd party component to
send a DataGrid or DataTable's contents to Excel? I've tried the following
code but it does not work reliably with large amounts of data (we have about
50,000 rows).

Server.ScriptTimeout = 1000;

Response.ContentType = "application/vnd.ms-excel";

Response.Charset = "";

EnableViewState = false;

System.IO.StringWriter stringWriter = new System.IO.StringWriter();

HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

DataGrid1.RenderControl(htmlWriter);

Response.Write(stringWriter.ToString());

Response.End();
 
B

billmiami2

An alternative that I use is to create a comma delimited text file by
looping through the datatable in the datagrid's datasource (no datagrid
needed, really) and using a streamwriter to create the file. Save it
with the suffix .csv to a location on the server and then provide the
user with a link to the new file. It will automatically open in Excel
in the browser.

Bill E.
Hollywood, FL
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top