Dukebaby
Dukebaby

Reputation:

asp.net DataPager, set PageIndex

I have a search that uses a ListView to display the results. I also use a DataPager to handle pagination of the results.

                                <asp:DataPager ID="dpProducts" PagedControlID="lvProducts" runat="server" PageSize="12">
                                    <Fields>
                                        <asp:NextPreviousPagerField PreviousPageText="< Prev" NextPageText="" />
                                        <asp:NumericPagerField ButtonCount="10" />
                                        <asp:NextPreviousPagerField NextPageText="Next >" PreviousPageText="" />
                                    </Fields>
                                </asp:DataPager>

This works great. My issue is when browsing search results lets say I go to page 3. I then decide to do a new search.

Now, the new search results are displayed, but I am on page 3 of them. I want the PageIndex of the DataPager to be reset back to 0 if I do a new search.

Is there a way I can do this either in the code-behind or on the .aspx page?

Upvotes: 5

Views: 6752

Answers (1)

Dukebaby
Dukebaby

Reputation:

I figured it out. In the _Click event I had to add this: dpProducts.SetPageProperties(0, int.Parse(ddlNumOfItems.SelectedValue), true);

Upvotes: 7

Related Questions