ASP. WebForm for Repeater paging through PagedDataSource

Source: Internet
Author: User

1.& Code Description1.
2. Code Description1. Flip Button        Front desk Two LinkButton (previous page, next page), set different CommandName, CommandArgument, bind the same OnCommand event,in the background OnCommand event, separate processing2.PagedDataSource    Convert raw data to DataView and bind toPagedDataSource, byPagedDataSource's built-in properties enable paging and page flipping, and finally binding toRepeater above 2.Code1.front End
<Asp:repeaterID= "Rptrreview"runat= "Server"OnItemCommand= "Rptrreview_itemcommand"Onitemdatabound= "Rptrreview_itemdatabound"  >    ......  </Asp:repeater><ulclass= "Pager">    <Liclass= "Previous"><Asp:linkbuttonID= "Lnkbtnprevious"runat= "Server"OnCommand= "Repeaterpagechange_command"CommandName= "Previous"CommandArgument= "-1" >&larr;Previous page</Asp:linkbutton></Li>    <Asp:labelID= "Lblpageindex"runat= "Server"Text= "1"style= "color: #428BCA; font-size:24px;"></Asp:label>    <Liclass= "Next"><Asp:linkbuttonID= "Lnkbtnnext"runat= "Server"OnCommand= "Repeaterpagechange_command"CommandName= "Next"CommandArgument= "1">Next page&rarr;</Asp:linkbutton></Li></ul>

2.code-behind
protected voidRepeaterpagechange_command (Objectsender, CommandEventArgs e) {PagedDataSource PDS=NewPagedDataSource (); Pds. DataSource=GETREVIEWDV ();//bind DataView to PagedDataSourcePds. AllowPaging =true;//sets a value that indicates whether paging is enabledPds. PageSize =3;//set the number to display on each page    intPageindex=convert.toint32 (LblPageIndex.Text.ToString ())-1; Pds. CurrentPageIndex= PageIndex;//get PagedDataSource Current page number    if(e.commandname=="Next"&&pds. Islastpage)//is already the last page, also page down the situation, skip{Rptrreview.datasource=PDS;    Rptrreview.databind (); }    Else if(E.commandname = ="Previous"&&pds. Isfirstpage)//is already the home page, also page up the situation, skip{Rptrreview.datasource=PDS;    Rptrreview.databind (); }    Else//Modify PagedDataSource page number by e.commandargument{PageIndex= PageIndex +Convert.ToInt32 (e.commandargument); Lblpageindex.text= (PageIndex +1).        ToString (); Pds. CurrentPageIndex= PageIndex;//sets the index of the current page. Rptrreview.datasource =PDS;    Rptrreview.databind (); }}

3. Compatible version
/// <summary>///page pageindex of binding Rptrreview/// </summary>/// <param name= "PageIndex" ></param>protected voidBindrptrreview (ref intPageIndex) {PagedDataSource PDS=NewPagedDataSource (); Pds. DataSource=GETREVIEWDV (); Pds. AllowPaging=true;//sets a value that indicates whether paging is enabledPds. PageSize =3;//set the number to display on each page//dealing with pageindex extreme situations    if(pageindex<0) {PageIndex=0; }    Else if(Pageindex> (PDS). pagecount-1) ) {PageIndex=pds. pagecount-1;} PDS. CurrentPageIndex= PageIndex;//sets the index of the current page. Rptrreview.datasource =PDS;    Rptrreview.databind (); }protected voidRepeaterpagechange_command (Objectsender, CommandEventArgs e) {    intPageIndex = Convert.ToInt32 (LblPageIndex.Text.ToString ())-1; PageIndex= PageIndex +Convert.ToInt32 (e.commandargument); Bindrptrreview (refPageIndex); Lblpageindex.text= (PageIndex +1). ToString ();}

 3.Reference http://www.cnblogs.com/ranran/p/4140511.htmlhttp://www.codeproject.com/Articles/37864/Repeater-with-Paging-and-Sorting-Features?msg=5149854# Xx5149854xxhttps://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.pageddatasource (v=vs.100). aspx from for notes (Wiz)



ASP. WebForm for Repeater paging through PagedDataSource

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.