Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a large data table containing articles published by staff to the corporate website. Users can select or not select various filters such as author and publish date, and press the Search button. The results are displayed on a paged GridView.

The underlying mechanism is that when the button is clicked, a SELECT string is generated using the filter criteria. If a filter is empty (say, the "Author" textbox is left blank) then the filter is not used. The SelectParameters property of the grid's associated SqlDataSource control is cleared and reset with the requested filters, the source's SelectCommand property is set with the new query, and the grid is bound. The page then displays the first page of data. All working exactly as expected.

The problem comes up when the user tries to navigate to a different page of data. There is a postback and the data is not reloaded, resulting in an empty grid. The behavior I want is that paging through the data will page through the data.

I understand the problem: the data is not persisting between loads. I suspect there is a straightforward way to manage this, but I haven't been able to figure that out yet. I have looked at reloading the data and manually setting PageIndex, but I haven't been able to figure out how to retrieve the requested page index.

Any suggestions?
Posted

Generally this is handled by persisting the filter and reapplying on postback by handling the PageIndexChanged[^] or PageIndexChanging[^] events
 
Share this answer
 
Try:
1. Enable the pagination of the GridView
2. Set EnableCaching property of the SQLDatasource

Have a look at this article for full detail:
Custom Paging and Caching of Data[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900