Pagination technology-GridView Control

Source: Internet
Author: User

Pagination technology for the GridView Control

 

Step 1: set the properties of the GridView control. The page-related attributes are as follows:

AllowPaging = "true": allowed pagination. PageSize = "size": Number of Information entries displayed on each page,

OnPageIndexChanging = "GridView1_PageIndexChanging": the event triggered when the page number changes.

 

Step 2: Set the PagerTemplate page attributes of the GridView control. PageTemplate is used to obtain or set custom content of the page navigation line in the GridView control. The code is implemented as follows:

<PagerTemplate> <table width => <tr> <td style => NO. <asp: Label ID = runat = Text => </asp: Label> <asp: label ID = runat = Text => </asp: Label> <asp: LinkButton ID = runat = CausesValidation = CommandArgument = CommandName = Text => </asp: LinkButton> <asp: linkButton ID = runat = CausesValidation = CommandArgument = CommandName = Text => </asp: LinkButton> <asp: linkButton ID = runat = CausesValidation = CommandArgument = CommandName = Text => </asp: LinkButton> <asp: linkButton ID = runat = CausesValidation = CommandArgument = CommandName = Text => </asp: LinkButton> <asp: TextBox ID = runat = Text = Width => </asp: textBox> <asp: LinkButton ID = runat = CausesValidation = CommandArgument = CommandName = Text => </asp: linkButton> </td> </tr> </table> </PagerTemplate>View Code

(GridView) Container. parent. parent ). pageIndex + 1 get the number of pages displayed by the current control; (GridView) Container. parent. parent ). pageCount obtains the total number of pages of the current control. When the CausesValidation setting button is submitted, verification is not executed. The CommandArgument setting is an optional parameter that is passed to the Command event handler along with the associated CommandName attribute; The CommandName setting Command name, the Command name is associated with the Button control that is passed to the Command event.

 

Step 3: implement the GridView1_PageIndexChanging event in the background. The Code is as follows:

Protected void GridView1_PageIndexChanging (object sender, GridViewPageEventArgs e) {// obtain the current gridview control gvw = (GridView) sender through type conversion; if (e. newPageIndex <0) {TextBox PageNum = (TextBox) GridView1.BottomPagerRow. findControl ("txtNewPageIndex"); int Pa = int. parse (PageNum. text); if (Pa <= 0) // if the index to go to the page is smaller than or equal to 0, it is switched to 0 {gvw. pageIndex = 0;} else {gvw. pageIndex = Pa-1 ;}} else {gvw. pageIndex = e. newPageIndex;} bind (); // bind a data function to a custom GridView control}

* For more information, please advise.

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.