Repeater Controls in ASP.NET

The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items.

Repeater is a Data Bind Control. Data Bind Controls are container controls. Data Binding is the process of creating a link between the data source and the presentation UI to display the data. ASP .Net provides rich and wide variety of controls, which can be bound to the data.

HeaderTemplate: This template is used for elements that you want to render once before your ItemTemplate section.

FooterTemplate: - This template is used for elements that you want to render once after your ItemTemplate section.

ItemTemplate: This template is used for elements that are rendered once per row of data. It is used to display records

AlternatingItemTemplate: This template is used for elements that are rendered every second row of data. This allows you to alternate background colors. It works on even number of records only.

SeperatorTemplate: It is used for elements to render between each row, such as line breaks.

Some point about Repeater Control

It is used to display backend result set. It is used to display multiple tuple.

It is an unformatted control. The Repeater control is a basic templated data-bound list. It has no built-in layout or styles, so you must explicitly declare all layout, formatting, and style tags within the control's templates.

The Repeater control is the only Web control that allows you to split markup tags across the templates. To create a table using templates, include the begin table tag (<table>) in the HeaderTemplate, a single table row tag (<tr>) in the ItemTemplate, and the end table tag (</table>) in the FooterTemplate.

The Repeater control has no built-in selection capabilities or editing support. You can use the ItemCommand event to process control events that are raised from the templates to the control.

We have to use scriptlets for data access.

Data Bind Control can display connected and disconnected model.

Data Bind Control have DataBind() method and DataBound event

-> DataBind()-> ItemCreated -> Event-> DataBound -> Event

System.Commom.Data namespace-> DBDataRecord Class

Controls -> Child Control

Every DataBindControl implement collection.

The data in DataSource is bound to Repeater using its DataBind Method. Once the data is bound, the format of each data item is defined by a template like ItemTemplate.

The ASP.NET Repeater Control will not render the result unless you bound it to a data source through its DataSource property.

Output of the above program

This article is for making a beginner learn and use Repeater Control.

Note: In the above example you have to change the connection string according to your database and data source.

Conclusion

I hope that this article would have helped you in understanding the Repeater Control in ASP.NET. Please share it if you know more about this article. Your feedback and constructive contributions are welcome.