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:
- Header Template
- ItemTemplate
- AlternatingItemTemplate
- SeparatorTemplate
- 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:
- PageSize
- This property defines
how many records are displayed on a page and it takes
an integer (by default it's set at 10).
- AllowPaging
- This property determines
whether the paging should be turned on or off (Boolean "true" or "false"). By
default it is set to "false".
- CurrentPageIndex
- This gets/sets the current
page number. By default it returns 0.
- PageCount
- Returns the total number
of pages that are available.
- DataSource
-
The value of this property will be the source
of the data which we want to page.
- IsFirstPage
- Returns "true" or "false".
It depends on whether the current page is the first page
in the series.
- 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