Repeater control combines with PagedDataSource to implement paging functionality

Source: Internet
Author: User

The

 repeater control implements its paging functionality in conjunction with PagedDataSource, which can be used if control developers need to provide paging support to custom data-bound controls

This article explains Repeater control and PagedDataSource to realize its paging function. The PagedDataSource class encapsulates properties that allow data source controls (such as the DataGrid, GridView) to perform paging operations. This class can be used if a control developer needs to provide paging support to a custom data-bound control.     PagedDataSource Partial public properties:    allowcustompaging//Gets or sets a value that indicates whether custom paging is enabled. AllowPaging//Gets or sets a value indicating whether paging is enabled. Count//Gets the number of items to be used from the data source. CurrentPageIndex//Gets or sets the index of the current page. DataSource//Gets or sets the data source. Datasourcecount//Gets the number of items in the data source. Firstindexinpage//Gets the first index in the page. iscustompagingenabled//Gets a value indicating whether the custom paging is enabled. Isfirstpage//Gets a value that indicates whether the current page is the homepage. Islastpage//Gets a value indicating whether the current page is the last page. ispagingenabled//Gets a value indicating whether paging is enabled. IsReadOnly//Gets a value indicating whether the data source is read-only. IsSynchronized//Gets a value that indicates whether access to the data source is synchronized (thread-safe). PageCount//Gets the total number of pages required to display all items in the data source. PageSize//Gets or sets the number of items to display on a single page. Virtualcount//Gets or sets the number of actual items in the data source when using custom paging.   Below is the PagedDataSource class implementation Repeater control's pagination display example, figure:      code as follows: protected void Page_Load (object sender, EventArgs e)   {  if (! Page.IsPostBack   {  int pageIndex = 1;  try  {  pageIndex = Convert.ToInt32 (request.querystring["Page");  if (pageIndex <= 0) pageIndex = 1; }  catch  {  pageIndex = 1; }&N Bsp DataTable dt = getdocumenttable ();  pageddatasource PDS = new PagedDataSource ();  PDS. DataSource = dt. DefaultView; Set up a data source   PDS. AllowPaging = true; Sets a value that indicates whether paging is enabled   PDS. PageSize = 5; Set the quantity   PDS to display on each page. CurrentPageIndex = pageIndex-1; Sets the index of the current page.   Rptdocumentlist.datasource = pds;  rptdocumentlist.databind ();  ltlpagebar.text = GetPageBar (PDS);  } } //page bar   private string Getpagebar (PagedDataSource pds)   {  string pagebar = STRING.E mpty;  int currentpageindex = PDS. CurrentPageIndex + 1;  if (CurrentPageIndex = 1)   {  Pagebar + + "Home"; }  else  {  Ebar + = "+ Request.currentexecutionfilepath +"? Page=1 "> Home"; }  if ((currentPageIndex-1) < 1)   {  Pagebar + + Previous page; }  else  {  Pagebar + = "+ requesT.currentexecutionfilepath + "? Page= "+ (currentPageIndex-1) +" "> prev"; }  if ((CurrentPageIndex + 1) > PDS. PageCount)   {  pagebar = "Next page"; }  else  {  Pagebar + + Request.currentexecutionfilepat H + "? Page= "+ (CurrentPageIndex + 1) +" "> Next"; }  if (CurrentPageIndex = PDS. PageCount)   {  Pagebar = "End"; }  else  {  Pagebar + = "+ Request.currentexecutionfilepath + "? Page= "+ PDS. PageCount + "" > Last "; }  return pagebar; } //Create test table   DataTable getdocumenttable ()   {&NB Sp DataTable dt = new DataTable ();  dt. Columns.Add ("DocumentID", typeof (int));  dt. Columns.Add ("Title", typeof (String));  for (int i = 1; I <= i++)   {  DataRow row = dt. NewRow ();  row["DocumentID"] = i;  row["title" = "Document title" + i + "";  dt. Rows.Add (Row); }  return dt; }   

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.