The implementation of the GridView pagination and the custom page-style feature instances

Source: Internet
Author: User
Tags prev
This article gives you a detailed introduction of the following GridView implementation pagination and custom pagination style, specific sample code as follows, there are want to learn friends can refer to ha, I hope to help you

Implementation of the GridView paging

Copy Code code as follows:


to join
in the GridView.

//Implementation Paging


allowpaging= "true"


//One page of data 10 rows


pagesize= "10"

Events that are triggered when
//paging


onpageindexchanging= "Gvwdesignationname_pageindexchanging"


In server events

Copy Code code as follows:


protectedvoid gvwdesignationname_pageindexchanging (object sender, Gridviewpageeventargs e)


{


Gvwdesignationname.pageindex=e.newindex;


Bingdesignatioonname ();


}


Here I give a generic display pagination template (search on the web, give a note myself)

Copy Code code as follows:


<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 paging is the first page, then the connection will not be displayed. At the same time, it corresponds to the command parameter commandargument of the self-identification


<asp:linkbutton id= "linkbuttonfirstpage" runat= "Server" commandargument= "the" "" A "commandname=" 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 be displayed


<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


<asp:textbox id= "Txtnewpageindex" runat= "Server" width= "20px" text= ' <%# (GridView) Container.Parent.Parent). PageIndex + 1%> '/> page


//here will be commandargument even if clicked 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

Copy Code code as follows:


protected void gvwdesignationname_pageindexchanging (object sender, Gridviewpageeventargs e)
{
//Get the control br> 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, gets the paging block to use Bottompagerrow or Toppagerrow, and of course adds HeaderRow and Footerrow
GridViewRow Pagerrow = Thegrid.bottompagerrow;
if (pagerrow!= null)
{
//Get text control
Txtnewpageindex = Pagerrow.findcontrol ("Txtnewpageindex") as Textbo X
}
if (txtnewpageindex!= null)
{
//Get index
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 the new value
Thegrid.pageindex = NewPageIndex;
//Rebind
Bingdesignatioonname ();
}

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.