Search code examples
c#asp.netlistviewpaginationdatapager

On page load, navigate to a specific page where a listviewitem belongs using listview and datapager?


I have the selected DataKey in session from the ListView.
I am able to set the selection back when I comeback to this aspx page containing listview.
But when the selected item in the listview belongs to some other page (not the first listview page) then I need to also set the selected listview page to the one, where my item belongs.

I use a listview and a datapager (with template paging)

How can I find, in which page my item to be selected exists?

Can I search for the datakey value's page and then activate it?


Solution

  • Well the simplest solution I could apply was to also save the pageindex on session.
    protected void ListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { CurrentPageSessionVariable = (e.StartRowIndex / e.maximumRows); }

    Now on pageload...
    dataPager1.SetPageProperties(CurrentPageSessionVariable * dataPager1.PageSize, dataPager1.MaximumRows, true);

    This will ensure that when we comeback to this page, the datapager is signaled to load the specified page and show the selected item(which is separate code).