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" >←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→</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