Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   gridView.DataBind();
}

whenever click the page number not display the clicking page in grid
Posted
Updated 10-Jan-12 18:12pm
v7
Comments
Karthik Harve 10-Jan-12 23:26pm    
[Edit] pre tags added.
Karthik Harve 10-Jan-12 23:26pm    
show the code for ShowGridBindData();.
Nigam Patel 10-Jan-12 23:36pm    
Question is not clear

Hi,
Use this,it works fine in my project:
XML
<asp:GridView ID="GridView1" runat="server" AllowPaging="true"
               onpageindexchanging="GridView1_PageIndexChanging">
           </asp:GridView>

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       GridView1.DataSource = GetData(); // GetData() is a method that will get Data from Database/Cache/Session to display in Grid.
       GridView1.DataBind();

       GridView1.PageIndex = e.NewPageIndex;
   }

Or else Use following links to get best examples with source code;
Paging and Sorting using Object Data Source[^]
Custom Gridveiw Control with Custom Pager, Check Box Column, Serial Number Column, Custom Navigation[^]
GridView all in one[^]
 
Share this answer
 
Hi,

I guess OnPageIndexChanging event is missing in your grid view defination.

Use the below code:

VB
<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False"
          AllowPaging="True" AllowSorting="True" onrowediting="grdView_RowEditing"
          onrowcancelingedit="grdView_RowCancelingEdit"
          onrowupdating="grdView_RowUpdating" EnableModelValidation="False"
OnPageIndexChanging="gridView_PageIndexChanging" > 


Also,
Save the dataset in a session variable say Session["gridrows"].
And ,in the gridView_PageIndexChanging method, write the code for

C#
//changing to new page
gridView.PageIndex = e.NewPageIndex;
//bind the data to grid.
griddview.DataSource = (DataSet)Session["gridrows"];
griddview.DataBind();


Hope this helps.
 
Share this answer
 
C#
protected void gv1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gv1.PageIndex = e.NewPageIndex;
   FillGrid(); //the function where u fill ur gridview
}
 
Share this answer
 
v4
Hi,

Create pagecIndexChanging even on your grid view:

C#
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   ShowGridBindData();
}
 
Share this answer
 
v2
Comments
2011999 10-Jan-12 23:54pm    
not working

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