ASP.NET export 50,000 records to Excel & generate Pivot Table

Hi experts

I have been searching the site & the web all over and can't find a decent solution. Here's my situation:

I'm using a datagrid (Infragistics UltraWebGrid) to display data on a page. The amount of data can range from 1 to max 50,000 records. I use AJAX to load 100 records at a time. Of course if the user gets a lot of results, then it would not be suitable to display this amount of data in a webpage, hence the user can export the data for further analysis to Excel (currently Excel 2003 at our company).

The infragistics UltraWebGrid offers a Excel Exporter, however this works extremely slowly when exporting large amounts of data. Exporting 50,000 records can take longer than 10 minutes. So I used the below code to speed things up.

What I cannot seem to do, is to add a template or a macro or a pivot table. My final solution should generate an Excel File with a pivot table. Is there any way to get the data from my ASP.NET page into an Excel 2003 document and display it using a pivot table? And this with fast performance?

Any help would be much appreciated!

Sub ExportToExcel()
        Dim dv As System.Data.DataView = sds_Assets.Select(DataSourceSelectArguments.Empty)
        Dim dt As System.Data.DataTable = dv.ToTable
        Dim dgGrid As New DataGrid()

        dgGrid.DataSource = dt
        dgGrid.HeaderStyle.Font.Bold = True
        Dim tw As New System.IO.StringWriter()
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)

        Dim attachment As String = "attachment; filename=FundTRX.xls"
        Response.AddHeader("content-disposition", attachment)
        Response.ContentType = "application/"
        Response.ContentEncoding = System.Text.Encoding.Default
    End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amandeep Singh BhullarCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
riffrackAuthor Commented:
Thanks a lot for the link. That is a fantastic solution for retrieving lots of data from a data source. However the database data source can only be a table and does not work with a view or a stored procedure. This is unfortunate, as most production websites never access the tables directly.

If I connect the devexpress grid up with a normal sqldatasource, it is slightly faster, but still far too slow. It is only very fast using the devexpress xpo data source, which only works with tables :-(

Do you or anyone else have any further ideas?
riffrackAuthor Commented:
I managed to find a working solution. Using Aman's recommendation and combining it with the following blog, I was able to find a superfast way of navigating in large datasets within the browser.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.