[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-11
5
Medium Priority
?
273 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Michael Sterling
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 2000 total points
ID: 36957552
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
 
LVL 1

Author Closing Comment

by:Michael Sterling
ID: 36957622
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
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36957625
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
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36957648
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
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36958154
Welcome, I'm glad you've solved your problem ;)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question