The Repeater Control
The repeater control is driven completely by templates. This allows you to output the control anyway you want it.
Templates of the repeater control
- ItemTemplate
- Required to display data
- Formats each item from the datasource
- HeaderTemplate
- Formats the content before the items from the dataSource
- FooterTemplate
- Formats the content after the items from the dataSOurce
- AlternatingItemTemplate
- Formats every other item from the dataSource
- SeperatorTemplate
- Formats between each item from the dataSource
Displaying Data
Use the itemTemplate to display data
This template is the only required template, all others are optional.
- Start a new WebSite in Visual Studio 2005
- Add a webform
- Drag a DataSource control to the page and configure it to a dataSource
- Drag a repeater control to the page
- Click the smart tag and configure it to the dataSource control

- Open the Source code view
- Type a
<
You choices show up in intellisense

Now you can add any formatting code you want as well as fields from the database
Add:
<%#Eval(“fieldname”)%>
Example:

The headerTemplate and footerTemplate can be used to start and stop tables or add other items to the beginning and the end of your data


Add an AlternatingItemTemplate tag
The order you declare the templates does not matter
Copy the same content from the itemtemplate
Add a class to the <tr> tag in the alternatingItemTemplate
Add a style in the head of the document
<style type=”text/css”>
.alternate
{
background-color:#cccccc;
}
</style>

The seperatorTemplate is used to add items between each data item