Why does my pager send me back to my default page instead of the next set of records?

I'm including the markup and code behind below but the sequence of events are as follows. I come to my default page which pulls some data and displays it to the user. The user then performs a search that pulls a different set of data into a GridView control. This GridView control contains a pager control. When the user clicks on the next button...instead of goin to the next group of records in the data, the page is redirected back to the default page with the original data (the data before the search was performed). Why? What am I doing wrong?
markup (HTML)
---------------------------------------------------------------
<asp:UpdatePanel runat="server" ID="upStudentLoginGrid" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gdvListOfStudents" runat="server" AutoGenerateColumns="false" CssClass="SignedInGrid"
            GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="10" PageIndex="0" OnPageIndexChanging="gdvListOfStudents_OnPageIndexChanging"
            PagerStyle-HorizontalAlign="Center" OnRowCommand="gdvListOfStudents_OnRowCommand" DataKeyNames="AthleteUid">
            <Columns>
            .
            .
            .
            </Columns>
            <PagerSettings Mode="NextPrevious" />
            <PagerStyle CssClass="Paging" />
            <PagerTemplate>
                <asp:LinkButton ID="PreviousLinkButton" runat="server" CommandArgument="Prev" CommandName="Page"
                    CssClass="PagerControl" />
                <asp:Label ID="PageDescriptionLabel" runat="server" Style="display: inline" CssClass="PagerControl" />
                <asp:LinkButton ID="NextLinkButton" runat="server" CommandArgument="Next" CommandName="Page"
                    CssClass="PagerControl" />
            </PagerTemplate>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>


code behind (C#)
------------------------------------------------------------
    private void BindData(StudentListBaseList studentList)
    {
        int pageSize = gdvListOfStudents.PageSize;
        int currentPage = gdvListOfStudents.PageIndex;
        int lastPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(studentList.Count / gdvListOfStudents.PageSize)));
        int maxCount = ((currentPage + 1) * gdvListOfStudents.PageSize);
        if (maxCount > studentList.Count) maxCount = studentList.Count;

        gdvListOfStudents.DataSource = studentList;
        gdvListOfStudents.DataBind();

        LinkButton prevLinkButton = gdvListOfStudents.BottomPagerRow.FindControl("PreviousLinkButton") as LinkButton; //<--HERE IS WHERE I GET THE NULL REFFERENCE
        LinkButton nextLinkButton = gdvListOfStudents.BottomPagerRow.FindControl("NextLinkButton") as LinkButton;
        Label pageDescriptionLabel = gdvListOfStudents.BottomPagerRow.FindControl("PageDescriptionLabel") as Label;
        prevLinkButton.Text = "< prev " + pageSize.ToString();
        nextLinkButton.Text = "next " + pageSize.ToString() + " >";


        prevLinkButton.Enabled = (currentPage > 0);
        nextLinkButton.Enabled = (currentPage < lastPage);
        pageDescriptionLabel.Text = String.Format("{0} to {1} of {2}", (currentPage * pageSize) + 1, maxCount, studentList.Count);


        gdvListOfStudents.Visible = true;
    }

Open in new window

LVL 1
Michael SterlingWeb Applications DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ivan_vaguninCommented:
Hi!
First I guess, user query is not preserved between postbacks - you should save it in view state and apply before data binding on every postback.

Then you need to handle page index changing event in a proper way to make pager work (you should set gridview current page index after data binding).

If you post full code, I'll try to give more specific advise. Hope this helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michael SterlingWeb Applications DeveloperAuthor Commented:
thanks. i found that i was actually doin something incorrect on my RowCommand method. I also decided to just go with the standard pager instead of customizing it. i'm not sure what all is involoved in making sure my data goes to the "next set of data" when if i were to try and customize what my pager looks like. but based on the code above, if i put the custom pager back in place, will the code that i currently in place work now?
0
Michael SterlingWeb Applications DeveloperAuthor Commented:
thanks. i found that i was actually doin something incorrect on my RowCommand method. I also decided to just go with the standard pager instead of customizing it. i'm not sure what all is involoved in making sure my data goes to the "next set of data" when if i were to try and customize what my pager looks like. but based on the code above, if i put the custom pager back in place, will the code that i currently in place work now?
0
Michael SterlingWeb Applications DeveloperAuthor Commented:
nevermind that last question...i put the custom pager back in the markup and it worked fine. the problem was my "wacky" code in the OnRowCommand method...thanks again..
0
ivan_vaguninCommented:
Welcome, I'm glad you've solved your problem ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.