Wednesday, September 29, 2010

Paging with Repeater Control

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:
1. Header Template2. ItemTemplate3. AlternatingItemTemplate4. SeparatorTemplate
5. FooterTemplateLet 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 .



Link Buttons:

These link Button placed outside of the repeator control

Add Image

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:

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:

No comments:

Post a Comment