GridView分页不工作

本文关键字:工作 分页 GridView | 更新日期: 2023-09-27 18:10:22

我有一个网格,我在页面init上使用这个代码

        UpagedList = new PagedListAdapter<User>(UserListGridView);
        UpagedList.MaxRows = ConfigurationService.DefaultPageSize;
        UserListGridView.PageIndexChanged += delegate
        {
            Presenter.FillDataOnDropDown();
        };
       UserListGridView.Sorting += new GridViewSortEventHandler(UserListGridView_Sorting);
       UserListGridView.Sorted += delegate {Presenter.SortChanged(); };

my grid code:

           <asp:GridView CssClass="Greed" ID="UserListGridView" runat="server" DataSourceID="ListUserDataSource"
              AutoGenerateColumns="false" EmptyDataText="No data found" DataKeyNames="Id" OnSorting="UserListGridView_Sorting" AllowSorting="True"
               PageSize="25" AllowPaging="True" GridLines="None" EnableViewState="false">
                   <Columns></Columns>
 </asp:GridView>

分页不工作…?我还需要为分页做些什么…当我点击第二页时页面没有变化但是数据被添加到网格

GridView分页不工作

我想你错过了gridview中的OnPageIndexChanging事件。尝试将此添加到gridview OnPageIndexChanging="UserListGridViewIndexChanging"在后端代码

protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
    {
        UserListGridView.PageIndex = e.NewPageIndex;
        Bind(); // you data bind code
    }

希望能有所帮助

protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
    UserListGridView.PageIndex = e.NewPageIndex;
    UserListGridView.DataBind();
    Bind(); // you data bind code is here 
}