Quantcast
Viewing all articles
Browse latest Browse all 82115

Using asp.net GridView with DataTables and Large DataSets

I have a custom grid control that inherits from the asp.net GridView. In the OnPreRender event it evaluates custom properties on my control and dynamically builds/registers a client script to use DataTables for paging, sorting, etc. client-side. The code-behind of each aspx page sets the grid DataSource and calls the DataBind. It also implements the DataBound and RowDataBound events of the GridView to manipulate the data and/or set additional properties on each row specific to data in the row (based on user permissions or other criteria). That's my set-up.

Here's my problem. When I have large datasets (say 1000 rows and over -- we do limit total number of rows returned to 5000 at the database level), the grid takes forever (can take several minutes if it finishes at all) to render. We set our paging up to chunk rows into page lengths of 10 to 25 rows most of the time, so I really want the rows of the active page to show up quickly. I have attemped a server-side implementation using bServerSide=true and sAjaxSource="some aspx page I built" but I can't get it to work the way I need it to. Since we are using the DataTables to enhance a GridView, the grid has to render before the DataTables script can be applied. I force the render by adding one empty dummy row in the code-behind (if I don't do that then the call to my sAjaxSource never happens). When my sAjaxSource page executes I can use the request params and get the subset of data for just the page we want to display, and return it in the proper JSON format for DataTables to display it on the page just fine. EXCEPT, I only have access to the DataBound and RowDataBound events of the GridView when I add my dummy row, before I ever get to my sAjaxSource page and get my real data. So my data doesn't look right when it displays. I need access during the binding events to mask data or add links to data, etc...the data is useless without those features.

I'd really like postback behaviour on paging and sorting, but with all the bells and whistles I've become accustomed to with DataTables. Then I could limit the data to the active grid page in my aspx page before calling the databind and also have access to the binding events for my masking and linking bells and whistles.

I tried going back to strictly client-side behaviour and using the bDeferRender=true property, but the documentation is pretty specific that it only works with Ajax or Javascript datasources so I wasn't surprised that it didn't help (in fact it made have made things worse).

Any advice on some other features or properties I might want to try?

Viewing all articles
Browse latest Browse all 82115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>