Alternate item template of the Repeater control

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.