ADO.NET 101: Data Rendering with a Repeater Control Introduction - Displaying Data from DataReader with a Repeater Control
(Page 2 of 4 )
IDE related details of Repeater Control
The next picture shows a Repeater Control placed on the design pane of a web form. The corresponding html generated is:
<asp:Repeater id="Repeater2" runat="server">
</asp:Repeater>
.
Since the repeater control orchestrates a series of html templates, it will be necessary to insert the html formatting into the control. The VS 2003 IDE gives a dropdown cue as to the different templates built-in for this purpose. As soon as you insert a < tag in the Repeater Control you will see this drop-down menu, from which the Header template has just been inserted. The header and footer templates serve the purpose of providing the information that is suggested by their names, for example the column names of a table in the header and some aggregate information, or date in the footer.
The ItemTemplate is where row after row of data gets in. The Header and Footer templates are rendered only once since they are needed only once. If they are not defined, they are not rendered. The Alternating ItemTemplate is a part of the same ItemTemplate but helps in optionally rendering the alternate rows of the ItemTemplate for better readability of data. Again, it is rendered only if it is defined, not otherwise. The ItemTemplate is however, mandatory.

Although the template tags are provided, what goes into the various templates will depend on the data that is going to be displayed, and any special formatting that may need to be applied. This next picture shows how a table is going to be inserted as a part of the Repeater Control, where a couple of columns with their column headings are inserted into the HeaderTemplate portion of the Repeater Control. How do I know what the columns are? Well, since I am designing this to bring in data from a data reader to the Repeater Control, I know a priori the field (column) names that are going to be displayed (review my SQLCommand's CommandText property in the next section).

Next: Configuring the Item >>
More ASP.NET Articles
More By Jayaram Krishnaswamy