我有一个网格,我在第121页上使用此代码
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(); };
我的网格代码:
<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>
分页不起作用......?我需要做什么才能进行分页...当我点击第二页页面时没有得到改变但是数据被附加在网格中
答案 0 :(得分:3)
我认为您错过了gridview中的OnPageIndexChanging
事件。尝试将此添加到您的gridview OnPageIndexChanging="UserListGridViewIndexChanging"
并在后端代码中
protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
UserListGridView.PageIndex = e.NewPageIndex;
Bind(); // you data bind code
}
希望这会有所帮助
答案 1 :(得分:1)
protected void UserListGridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
UserListGridView.PageIndex = e.NewPageIndex;
UserListGridView.DataBind();
Bind(); // you data bind code is here
}