Methods for paging repeater controls using the SQL paging method

Source: Internet
Author: User

Page code
<divclass="Booklist"> <asp:repeater id="Rpbooks"runat="Server"> <HeaderTemplate> <ulclass="title"> <liclass="bname"> Title </li> <liclass="Bauthor"> Author </li> <liclass="Bprice"> Prices </li> </ul> </HeaderTemplate> <ItemTemplate> <ulclass="Data"> <liclass="bname"><% #eval_r ("title"). ToString (). Length > -? Eval_r ("title"). ToString (). Substring (0, -)+"...": Eval_r ("title"). ToString ()%></li> <liclass="Bauthor"><% #eval_r ("author"). ToString (). Length > -? Eval_r ("author"). ToString (). Substring (0, -) +"...": Eval_r ("author"). ToString ()%></li> <liclass="Bprice"><% #eval_r ("UnitPrice")%></li> </ul> </ItemTemplate> <AlternatingItemTemplate> <ulclass="Data"style="Background-color:gray;"> <liclass="bname"><% #eval_r ("title"). ToString (). Length > -? Eval_r ("title"). ToString (). Substring (0, -)+"...": Eval_r ("title"). ToString ()%></li> <liclass="Bauthor"><% #eval_r ("author"). ToString (). Length > -? Eval_r ("author"). ToString (). Substring (0, -) +"...": Eval_r ("author"). ToString ()%></li> <liclass="Bprice"><% #eval_r ("UnitPrice")%></li> </ul> </AlternatingItemTemplate> </asp:repeater><div style="Clear:both;"></div><!--Paging Jump--><pclass="page"><asp:linkbutton id="Lbtnfirst"Commandname=" First"runat="Server"Oncommand="Lbtnfirst_command"> Home </asp:LinkButton> <asp:linkbutton id="lbtnprevious"Commandname="previous"runat="Server"Oncommand="Lbtnfirst_command"> Prev </asp:LinkButton> <asp:label id="Lblpageindex"runat="Server"text="1"></asp:Label> <asp:label id="Label3"runat="Server"text="/"></asp:Label> <asp:label id="Lblpagesum"runat="Server"text=""></asp:Label>&nbsp; <asp:linkbutton id="Lbtnnext"Commandname="Next"runat="Server"Oncommand="Lbtnfirst_command"> Next </asp:LinkButton> <asp:linkbutton id="Lbtnlast"Commandname=" Last"runat="Server"Oncommand="Lbtnfirst_command"> Last </asp:LinkButton>Jump to<asp:textbox id="Txtpageindex"runat="Server"Width="30px"></asp:textbox><asp:button id="Btngo"runat="Server"text="Jump to"Commandname="btn"OnCommand="Lbtnfirst_command"/>Total<asp:label id="Lblcount"runat="Server"text="Label"></asp:Label>article Records</p> </div>
Post Code
 intindex =1;//initializes the current page index, showing the first page by default    intPageSize =5;//set the number of bars to display per pageCommon.page Page =NULL; protected voidPage_Load (Objectsender, EventArgs e) {          //The previous section of the code to the current page label default to the first page, with a label to save the current page indexindex =int.        Parse (Lblpageindex.text); //load Total pages, total number of records, and list of information when the page is first loaded        if(!IsPostBack) {Page=Newcommon.page (index, pageSize);  This. Lblcount.text =page.            Count.tostring ();  This. Lblpagesum.text =page.            Pagesum.tostring ();        Bookbind (); }    }    //page Turn button command event    protected voidLbtnfirst_command (Objectsender, CommandEventArgs e) {Page=Newcommon.page (index, pageSize); stringCommandName =E.commandname; Switch(commandName) { Case " First": page. PageIndex=1;  Break;  Case "previous":                if(index==1) {page. PageIndex=1; }                Else{page. PageIndex=index-1; }                 Break;  Case "Next":                if(Index = =page. pagesum) {page. PageIndex=page.                Pagesum; }                Else{page. PageIndex=index+1; }                 Break;  Case " Last": page. PageIndex=page.                Pagesum;  Break;  Case "btn": page. PageIndex=int.                Parse (Txtpageindex.text);  Break; }         This. Lblpageindex.text =page.        Pageindex.tostring ();    Bookbind (); }    //binding data to repeater controls    Private voidBookbind () { This. Rpbooks.datasource =page.        Curpager;  This. Rpbooks.databind (); }    //How to get the total number of records     Public intGetCount () {returnpage.    Count; }    //How to get the total number of pages     Public intgetpagesum () {returnpage.    Pagesum; } 
Precautions

This example uses the label label to save the current page index, or it can be saved using view state.

Methods for paging repeater controls using the SQL paging method

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.