What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9765 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Paging with Repeater Control

Paging with Repeater Control

1 vote(s)
Rating: 5 out of 5
Article posted by Ganeshji on 8/6/2010 | Views: 33136 | Category: ASP.NET | Level: Beginner red flag


Repeater doesn't have an in-built feature of paging. But we can use paging in it by using PagedDataSource class. Let me explain it in details.

Introduction

The Repeater control is a data-bound control. It uses templates to display data. It lacks the built-in support for paging, editing and sorting. The Repeater control may be bound to a database table, and an XML file. In this control, the content and layout of list items is defined using Templates. Every Repeater must define an ItemTemplate.

Templates:


There are 5 templates available for a Repeater:

  1. Header Template
  2. ItemTemplate
  3. AlternatingItemTemplate
  4. SeparatorTemplate
  5. FooterTemplate

 

Let me discuss these templates in details:


HeaderTemplate: It is used to specify an optional header row. It is used to   determine the content and layout of the list header. 

ItemTemplate :It is used to define the content and layout of items within the list.

AlternatingItemTemplate: This template is used for elements that are rendered every second row of data. This allows you to alternate background colors.

SeparatorTemplate: The SeparatorTemplate is rendered between each row.

FooterTemplate: It is used to specify an optional footer row. It is used to determine the content and layout of the list footer.  


All these 5 templates will be placed within the Repeater .

Header Template



ItemTemplate




AlternatingTemplate


Footer Template



SeparatorTemplate







Link Buttons


These LinkButtons will be placed outside the Repeater Control.





Pagination in Repeater:


Repeater doesn’t support  Paging directly. But we can implement Paging in Repeater by using PagedDataSource.

PagedDataSource

This class comes from the System.Data.Web.UI.WebControls namespace, so we need not import any additional namespace to the page.

 

This class encapsulates the paging related properties of a data-bound control.
Few properties of PagedDataSource class are as follows:

  1. PageSize - This property defines how many records are displayed on a page and  it takes an integer (by default it's set at 10).
  2. AllowPaging - This property determines whether the paging should be turned on or off (Boolean "true" or "false"). By default it is set to "false".
  3. CurrentPageIndex - This gets/sets the current page number. By default it returns 0.
  4. PageCount - Returns the total number of pages that are available.
  5. DataSource - The value of this property will be the source of the data which we want to page.
  6. IsFirstPage - Returns "true" or "false". It  depends on whether the current page is the first page in the series.
  7. IsLastPage -- Returns "true" or "false". It  depends on whether the current page is the last page in the series.

Connection Object and Property Decleration follows:





Code for Page_Load Event





Code written in BringData() method




Here I have created an instance of the PagedDataSource class. In the next line, I had set the DataSource In the following  line  the AllowPaging property is to "true". And on the next line  the PageSize property is set to 3.


Code for Previous/Next Buttons







Contents of the Table tblUser






Output


The output is as follows:





The second page is as follows:
On clicking the NxtPage  Link Button the following output appears. If I click on the PrevPage Link Button we can go the the previous page.




Conclusion


This is all about Repeater Control. Hope u all enjoy reading it. Please provide me feedback on it, if any improvements required.

Reference:

  • http://articles. sitepoint.com/article/asp-nets-pageddatasource
  • http://www. dotnetspark.com/kb/697-pagination-repeater-datalist-control-asp-net.aspx
  • http://www. codeguru.com/csharp/.net/net_asp/controls/article.php/c12925

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:
Member since:Saturday, July 24, 2010
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Nagarajsoft | Posted on: 10 Aug 2010 05:27:15 AM

Nice article..

Posted by: Mspace | Posted on: 07 Jun 2012 03:21:30 AM | Points: 25

Hello,

Thank you for you nice article.
I have a problem. I use an updatepanel and I put all the controls inside it. The paging works fine but I would like to bring the first values on page load without the user needs to click on the next button
Thank you

>> Write Response - Respond to this post and get points
Related Posts

In the process of developing an application, there are situations when you need to pass a particular value from user control to its calling page. This article describes solution to that type of problem in an easy to follow steps.

To perform data manipulation (CRUD - Create, Read, Update and Delete) in the ListView, we can follow this approach.

In this article we shall learn how to fire Server Side method on click of the button, how to access the CommandName property of the asp: Button (using OnCommand event) and what is the use of it and how to access the CommandName property of the asp:Button (using OnClick event) and what is the use of it.

In this article we shall learn how to validate a TextBox as a mandatory field, how to validate a DropDownList / ListBox and What is Cause Validation property and how to avoid validation on clicking of a button.

In this article, we are going to learn how to set the expiration date and time for the cookies created in ASP.NET.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 2:42:25 PM