DataGrid - Sorting & Paging

  • Thread starter Thread starter pmanno
  • Start date Start date
P

pmanno

If I have a page with a DataGrid that is bound to a DataTable that is
populated by a query to a database and I want to enable sorting and
paging, do I have to add the DataTable to the cache or will the
viewstate hold the contents of the DataTable?

Basically, I want to avoid hitting the database wherever I can. It
seems that the DataTable has to be cached and the DataGrid re-bound, or
the DataTable has to be re-populated from the database and the DataGrid
re-bound whenever a postback occurs since the DataTable and therefore
the data which is bound to the grid is discarded once the page renders.

Thanks.
 
Viewstate will only hold the contents of the grid. By contents I mean the
HTML generated to display the contents of the data source.

The datatable itself will not be there. So you have to recreate it, sort,
and rebind.
 
You need to add it to the cache, then re-sort it each page load

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 

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

Back
Top