AlternatingitemtemplateDefines the content and layout of the alternate items. The so-called alternate item Mode means that the Repeater control and the datalist control allow parity items to display data in different content and layout forms, the odd number of rows is defined by the alternatingitemtemplate template (index number starts from 1), and the even number of rows are defined by the itemtemplate template (quotation marks start from 0 ). If only the itemtemplate template is defined and the alternatingitemtemplate template is not defined, all rows are displayed in the data and layout format specified by the itemtemplate template. If only the alternatingitemtemplate template is defined and the itemtemplate template is not defined, only odd rows of data specified by the alternatingitemtemplate template and layout form are displayed, and even rows are not displayed. If neither of the two templates is defined, no data is displayed, Which is meaningless.
The HTML tag of the alternatingitemtemplate template is:
<Alternatingitemtemplate>
<% -- Content and layout displayed in the template -- %>
</Alternatingitemtemplate>
Because the alternatingitemtemplate template contains data items, the repeater control must also bind data when using this template. The binding method is the same as that of the itemtemplate template.
To describe how to use the alternatingitemtemplate template and its effect, add an alternatingitemtemplate in the preceding example. The HTML view of the page becomes the following form.
<Form ID = "form1" method = "Post" runat = "server">
<% = "Product Name origin unit price" %> <% -- display the Repeater control header -- %>
<Asp: repeater id = "repeater1" runat = "server">
<Alternatingitemtemplate>
<Font face = "" color = "# ff0000">
<P>
<B> <% # databinder. eval (container. dataitem, "item name") %> </B>
<B> <% # databinder. eval (container. dataitem, "Origin") %> </B>
<B> <% # databinder. eval (container. dataitem, "unit price") %> </B>
</P>
</Font>
</Alternatingitemtemplate>
<Itemtemplate>
<Font face = "" color = "# 0000ff">
<P>
<% # Databinder. eval (container. dataitem, "item name") %>
<% # Databinder. eval (container. dataitem, "Origin") %>
<% # Databinder. eval (container. dataitem, "unit price") %>
</P>
</Font>
</Itemtemplate>
</ASP: repeater>
</Form>
A <alternatingitemtemplate> label is added to the <asp: repeater> label, which is an alternative tag. The data items specified by the alternate item template are the same as those specified by the item template. they display the same field data, but the text font and color are different.
You do not need to modify any background code. Press Ctrl + F5 to run the program, as shown in figure.
The alternatingitemtemplate alternate item template defines red bold characters, while the itemtemplate defines blue, which makes some changes to the page.