Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 281889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:14:30+00:00 2026-05-12T05:14:30+00:00

Take the following example…a page with a ListView and a DataPager used for paging

  • 0

Take the following example…a page with a ListView and a DataPager used for paging the data of the ListView:

Code Behind:

protected void Page_Load(object sender, EventArgs e)
{
    MyList.DataSource = GetSomeList();
    MyList.DataBind();
}

Source:

<asp:ListView ID="MyList" runat="server">
    <% //LayoutTemplate and ItemTemplate removed for the example %>
</asp:ListView>

<asp:DataPager ID="ListPager" PagedControlID="MyList" runat="server" PageSize="10">
    <Fields>
        <asp:NumericPagerField  />
    </Fields>
</asp:DataPager>

The problem with the DataPager is that it is always a step-behind with the binding.

For example, when the page loads it’s on page number 1. Then when you click on page 3, it stays on page 1 after the postback. Then you click on page 5, and after the postback it finds itself on page 3…and after that you click on page 6, and it finds itself on page 5…and so on and so forth.

Why isn’t the paging working as expected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:14:30+00:00Added an answer on May 12, 2026 at 5:14 am

    Solution

    The problem is due to the binding occuring on the Page_Load event.

    For this to work as expected, the binding needs to happen in the DataPager‘s OnPreRender event, not in the Page_Load.

    Source:

    <asp:DataPager ID="ListPager" PagedControlID="MyList" runat="server" PageSize="10"
        OnPreRender="ListPager_PreRender">
    
    <Fields>
            <asp:NumericPagerField  />
        </Fields>
    </asp:DataPager>
    

    Code Behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        //Binding code moved from Page_Load
        //to the ListView's PreRender event
    }
    
    protected void ListPager_PreRender(object sender, EventArgs e)
    {
        MyList.DataSource = GetSomeList();
        MyList.DataBind();    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following code for example; if (Convert.ToString(frm.WindowState) == Minimized) Layout.WindowState = Maximized; else
I am just wondering to take the following example: public void main() { int
Take the following example: public void init() { final Environment env = new Environment();
Take the following example: clear all Name1 = {'Data1','Data2','Data3','Data4'}; Data = {6.2,6,3.2,8}; CombnsName =
Take the following example: class BookManager { ... }; class Book { public: void
Take the following code example: File package1/__init__.py : from moduleB import foo print moduleB.__name__
Take the following example, class Cup {} class MyObject { protected $cups = array();
Take following example of code: (ASP.NET WebForms) <asp:Content ContentPlaceHolderID=Contents runat=server> <div class=blogpost-list> <asp:Repeater ID=blogList
Take the following example, I have a class public class SomeItem { public string
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.