Rocky Rocky - 4 months ago 37
ASP.NET (C#) Question

GridView Paging is not working?

I have a grid in that i am using this code on page init

UpagedList = new PagedListAdapter<User>(UserListGridView);
UpagedList.MaxRows = ConfigurationService.DefaultPageSize;
UserListGridView.PageIndexChanged += delegate
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">

Paging is not working...? what else i need to do for paging.. when i am clicking on 2nd page page is not getting change but data is getting appended in grid


I think you missing the OnPageIndexChanging event in the gridview. Try adding this to your gridview OnPageIndexChanging="UserListGridViewIndexChanging" and in the backend code

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

hope this helps