DataGrid - Sorting & Paging

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.
 
M

Marina

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.
 
J

John Timney \(ASP.NET MVP\)

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top