ASP.Net : DataPager Control always a step behind with paging

后端 未结 6 934
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 16:28

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

Code Behind:

6条回答
  •  春和景丽
    2020-12-14 17:21

    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:

    
    
    
            
        
    
    

    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();    
    }
    

提交回复
热议问题