Click here to Skip to main content
15,797,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to handle the PageIndexChanging event in the DataGrid ??
after setting it's AllowPaging value = true
Posted
Updated 4-May-11 3:38am
v2

Above provided solution by Mahendra.p25 is good as far as data are not larger.

For the larger records(may be 2000 up), this method may degrade the performance in terms of speed.So if you are targeting larger records in the DataGrid, go with custom paging.

Custom paging is method in which records are populated from database on demand. Let's consider you have page size of 20. So in the first page, only 20 records are needed. If use clicks on 2nd page, then data of that page should be loaded at that time and not at the page -1. Please find the links below for the custom paging implementation.

I would also suggest you to implement a custom control of the paging, so that you can re-use anywhere in the applicable and also in other applications as well.

Reference Link-1[^]

Reference Link-2[^]
 
Share this answer
 
try this

C#
//OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGrid();
        }
 
Share this answer
 
Quote:
//OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Gridview1.Databind();
}



VB
Protected Sub TypesGrid_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles TypesGrid.PageIndexChanging
       TypesGrid.PageIndex = e.NewPageIndex
       TypesGrid.DataBind()
   End Sub
 
Share this answer
 
v2
thanx Mahendra.p25 for replying
but still the error


protected void OrgGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
OrgGridView.PageIndex = e.NewPageIndex;
this.DataBind();
}

note the GridViewSelectEventArgs
not GridViewPageEventArgs
 
Share this answer
 
Comments
nagendrathecoder 4-May-11 8:57am    
Add comment to that particular user, then only he/she will receive a mail and came to know that you have problem.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}
i agree with this answer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900