Copy Code code as follows:
To add the following attributes to the GridView (foreground or backstage look at your habits.) )
Implementing pagination
Allowpaging= "true"
One page of data 10 rows
Pagesize= "10"
Events that are triggered when paging
Onpageindexchanging= "Gvwdesignationname_pageindexchanging"
In server events
protected void Gvwdesignationname_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Gvwdesignationname.pageindex=e.newindex;
Bingdesignatioonname ();
}
Here I give a generic display pagination template
<PagerTemplate>
Current article:
(GridView) Container.namingcontainer) is to get the current control
<asp:label id= "Labelcurrentpage" runat= "Server" text= "<%# ((GridView) container.namingcontainer). PageIndex + 1%> "></asp:Label>
Page/Total:
Get the total number of paging pages
<asp:label id= "Labelpagecount" runat= "Server" text= "<%# ((GridView) container.namingcontainer). PageCount%> "></asp:Label>
Page
If the page is the first page, then the connection will not be displayed. At the same time, the command parameter commandargument with self-identification is corresponding.
<asp:linkbutton id= "Linkbuttonfirstpage" runat= "Server" commandargument= "a", "Page"
Visible= ' <%# (GridView) container.namingcontainer). PageIndex!= 0%> ' > Home </asp:LinkButton>
<asp:linkbutton id= "Linkbuttonpreviouspage" runat= "Server" commandargument= "Prev"
Commandname= "Page" visible= ' <%# (GridView) container.namingcontainer). PageIndex!= 0%> ' > prev </asp:LinkButton>
If the paging is the last, then the connection will not display
<asp:linkbutton id= "Linkbuttonnextpage" runat= "Server" commandargument= "Next" commandname= "Page"
Visible= ' <%# (GridView) container.namingcontainer). PageIndex!= ((GridView) container.namingcontainer). PageCount-1%> ' > next page </asp:LinkButton>
<asp:linkbutton id= "Linkbuttonlastpage" runat= "Server" commandargument= "last" commandname= "Page"
Visible= ' <%# (GridView) container.namingcontainer). PageIndex!= ((GridView) container.namingcontainer). PageCount-1%> ' > Last </asp:LinkButton>
Go to Page
<asp:textbox id= "Txtnewpageindex" runat= "Server" width= "20px" text= ' <%# (GridView) Container.Parent.Parent). PageIndex + 1%> '/> page
Here will commandargument even click the button E.newindex value is 3
<asp:linkbutton id= "Btngo" runat= "Server" causesvalidation= "False" commandargument= "-2"
Commandname= "Page" text= "Go"/>
</PagerTemplate>
The code for the event should be
protected void Gvwdesignationname_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Get the control
GridView Thegrid = sender as GridView;
int newpageindex = 0;
if (e.newpageindex==-3)
{
Click the Go button
TextBox txtnewpageindex = null;
The GridView provides more APIs than the DataGrid, acquiring paging blocks that can use Bottompagerrow or Toppagerrow, and of course adding headerrow and Footerrow
GridViewRow pagerrow = Thegrid.bottompagerrow;
if (Pagerrow!= null)
{
Get the text control
Txtnewpageindex = Pagerrow.findcontrol ("Txtnewpageindex") as TextBox;
}
if (txtnewpageindex!= null)
{
Get indexed
NewPageIndex = Int. Parse (Txtnewpageindex.text)-1;
}
}
Else
{
Click on the other button
NewPageIndex = E.newpageindex;
}
Prevent new Index Overflow
NewPageIndex = NewPageIndex < 0? 0:newpageindex;
NewPageIndex = NewPageIndex >= thegrid.pagecount? Thegrid.pagecount-1: NewPageIndex;
Get a new value
Thegrid.pageindex = NewPageIndex;
Re-bind
Bingdesignatioonname ();
}