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.