Is there a way to find out what page a ListView item is on and to programmatically go to that page? I have a ListView with a DataPager that controls the paging. The reason for this is that, if I am on Page 2 of the ListView and I navigate away from the page, when I go back, I want to go back to the ListView page I was previously on.
A:
You should be able to store the PageIndex property in ViewState.
If you're "navigating away" as in closing the browser or going to another site which invalidates your ViewState, you can set PageIndex via QueryString in Page_Load.
That way, you can access myPage.aspx?page=2 from a bookmark.
Jim Schubert
2009-12-16 20:00:00
`ListView` doesn't have a `PageIndex` property
SLaks
2009-12-16 20:01:21
Yeah, I am going to do it in a query string, but as SLaks pointed out, I can't find a PageIndex property for ListView.
Xaisoft
2009-12-16 20:02:45
There's a pretty good write up of how to simulate paging in a ListView here: http://leedumond.com/blog/resetting-the-page-index-in-a-listview/
cfeduke
2009-12-16 20:09:20
Probably the best and most scalable way to do this is to retrieve your objects via stored procedure. or, if you have a list of objects, use LINQ's .skip(startrecord).take(pagesize) combination and bind the list view on every postback. I recently had to take this approach with 7,000+ records being returned.
Jim Schubert
2009-12-16 20:46:54
A:
You can get an item's index using the DisplayIndex property.
You can figure out what page it's on by dividing DisplayIndex by the DataPager's PageSize property.
You can set the current page by calling the DataPager's SetPageProperties method.
SLaks
2009-12-16 20:05:06