When you develop a database-driven ASP.NET application, you need to bind the data stored in a database table to one or more controls on the page so that it can be displayed to the user. Data binding refers to the process of dynamically assigning a value to a property of a control at runtime.
Example 6: Data Binding
Output:
Binding Data to a Repeater Control
The Repeater control is used to display data from a database.
Example 7: Repeater Control
Output:
Applying Templates
The Repeater control has no user interface of its own like say a TextBox control. A template is used to control formatting. The Repeater control supports five types of templates:
• HeaderTemplate: It controls how the header of the control is formatted.
• ItemTemplate: It controls how each item shown by the control is formatted.
• AlternatingItemTemplate: It controls how alternating items shown by the control are formatted.
• SeparatorTemplate: It displays a separator between each item displayed by the control.
• FooterTemplate: It controls how the footer of the control is formatted.
You can place HTML tags, other controls, and even ASP.NET inline code within templates. Suppose you had to show items in blue and alternating items in red, you would write the following code: