ListView with DataPager not working

后端 未结 7 926
[愿得一人]
[愿得一人] 2021-02-07 05:00

From everything I\'ve read, it seemed that adding paging to a ListView control should be dead simple, but it\'s not working for me. After adding the ListView and DataPager contr

7条回答
  •  春和景丽
    2021-02-07 05:29

    We need to databind list view again in OnPreRender event.

    protected override void OnPreRender(EventArgs e)
            {
                ListView1.DataBind();
                base.OnPreRender(e);
            }
    

    --Update

    After working on a few list views with asp.net ajax, I saw a solution that makes more sense than the above one. You would normally data bind Listview on page load method or a button click event handler and when there is post back the data binding would be lost as described above in the problem. So, we need to data bind again on page properties changed event handler for the list view.

    ListView_PagePropertiesChanged(object sender, EventArgs e)
    {
    ListView.DataSource=someDatasource;
    ListView.DataBind()
    }
    

提交回复
热议问题