20150410---GridView Paging (Memo)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.