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.
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.
There are 5 templates available
for a Repeater:
- Header Template
Let me discuss these templates
It is used to specify an optional header row.
It is used to determine the content and layout
of the list header.
is used to define the content and layout of items within the list.
This template is used for elements that are rendered every second row of data. This
allows you to alternate background colors.
The SeparatorTemplate is rendered
between each row.
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 .
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.
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:
- This property defines
how many records are displayed on a page and it takes
an integer (by default it's set at 10).
- This property determines
whether the paging should be turned on or off (Boolean "true" or "false"). By
default it is set to "false".
- This gets/sets the current
page number. By default it returns 0.
- Returns the total number
of pages that are available.
The value of this property will be the source
of the data which we want to page.
- Returns "true" or "false".
It depends on whether the current page is the first page
in the series.
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
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
Code for Previous/Next Buttons
Contents of the Table tblUser
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.
This is all about Repeater Control. Hope u all enjoy reading it. Please provide
me feedback on it, if any improvements required.
- 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