The GridView features a paging feature, but the template is single and less data is tried.
Allowpaging= "true"
Pagesize= "10"
Enable paging settings. The default number per page is 10
To add a paging trigger event:
Onpageindexchanging= "Gridview1_pageindexchanging"
<PagerTemplate>Current section:<%--(GridView) container.namingcontainer) just to get the current control--%> <Asp:labelID= "Labelcurrentpage"runat= "Server"Text= "<%# ((GridView) container.namingcontainer). PageIndex + 1%> "></Asp:label>page/Total:<%-- //get the total number of pagination pages--%> <Asp:labelID= "Labelpagecount"runat= "Server"Text= "<%# ((GridView) container.namingcontainer). PageCount%> "></Asp:label>page<%--//If the page is the first page, the connection will not be displayed. Also corresponds to the command parameters of the self-identification commandargument--%> <Asp:linkbuttonID= "Linkbuttonfirstpage"runat= "Server"CommandArgument= "First"
CommandName= "page"Visible= ' <%# ((GridView) container.namingcontainer). PageIndex!= 0%>' > Home</Asp:linkbutton> <Asp:linkbuttonID= "Linkbuttonpreviouspage"runat= "Server"CommandArgument= "Prev"CommandName= "page"Visible= ' <%#(GridView) container.namingcontainer). PageIndex!= 0%>' > Previous page</Asp:linkbutton><%-- //If the page is last, the connection is not displayed--%> <Asp:linkbuttonID= "Linkbuttonnextpage"runat= "Server"CommandArgument= "Next"CommandName= "page"Visible= ' <%#(GridView) container.namingcontainer). PageIndex!= ((GridView) container.namingcontainer). PageCount-1%>' > Next page</Asp:linkbutton> <Asp:linkbuttonID= "Linkbuttonlastpage"runat= "Server"CommandArgument= "Last"CommandName= "page"Visible= ' <%#(GridView) container.namingcontainer). PageIndex!= ((GridView) container.namingcontainer). PageCount-1%>' > Last</Asp:linkbutton>go to page
<Asp:textboxID= "Txtnewpageindex"runat= "Server"Width= "20px"Text= ' <%#(GridView) Container.Parent.Parent). PageIndex + 1>' borderstyle= ' None '/> page<%--//This will commandargument even if you click the button E.newindex value is 3--%> <Asp:linkbuttonID= "Btngo"runat= "Server"CausesValidation= "False"CommandArgument= "-2"CommandName= "page"Text= "GO"/></PagerTemplate>
Here is the addition of a paging trigger event (C # background code):
Gridview1_pageindexchanging
protected voidGridview2_pageindexchanging (Objectsender, Gridviewpageeventargs e) { //Get the controlGridView Thegrid = Sender asGridView; intNewPageIndex =0; if(E.newpageindex = =-3) { //Click the Go buttonTextBox Txtnewpageindex =NULL; //The GridView provides more APIs than the DataGrid, getting the paging block to use Bottompagerrow or Toppagerrow, and of course adding headerrow and FooterrowGridViewRow Pagerrow =Thegrid.bottompagerrow; if(Pagerrow! =NULL) { //get the text controlTxtnewpageindex = Pagerrow.findcontrol ("Txtnewpageindex") asTextBox; } if(Txtnewpageindex! =NULL) { //get indexedNewPageIndex =int. Parse (Txtnewpageindex.text)-1; } } Else { //Click on the other buttonNewPageIndex =E.newpageindex; } //prevent new Index overflowNewPageIndex = NewPageIndex <0?0: NewPageIndex; NewPageIndex= NewPageIndex >= thegrid.pagecount? Thegrid.pagecount-1: NewPageIndex; //get the new valueThegrid.pageindex =NewPageIndex; //re-bindbind (); }
End-of-page style:
20150410---GridView Paging (Memo)