[HTML]View Plaincopyprint?
- <table>
- <tr>
- <TD> User Number </td>
- </tr>
- <asp:repeater id="Rptuser" runat= "server">
- <ItemTemplate>
- <tr style=' background-color:<%# (container.itemindex%2==0)? " Red ":" Green "%>>
- <TD><% #Eval ("UID")%></td>
- </tr>
- </ItemTemplate>
- </asp:repeater>
- </table>
In an ASP. Repeater, it is sometimes necessary to change the color of interlaced. If an odd line shows one color, even rows show another color. As shown, today look at a little bit of skill when binding repeater.
[HTML]View Plaincopyprint?
- <ul id="list">
- <asp:repeater id="rpttest" runat= "server">
- <ItemTemplate>
- <Li class="odd"><% #Container. itemindex+1%;. <% #Eval ("Title")%></li>
- </ItemTemplate>
- <alternatingitemtemplate>
- <Li class="even"><% #Container. itemindex+1%;. <% #Eval ("Title")%></li>
- </alternatingitemtemplate>
- </asp:repeater>
- </ul>
The
shows that <AlternatingItemTemplate></AlternatingItemTemplate> is used for the interval color change. Next, you can do this by setting it slightly in the style. as follows:
#list { List-style:none; width:330px;} #list li{ Background: #50A3E5; margin-top:5px;} .odd{color: white;} .even{color: yellow;}
Finally, the <% #container is used to bind the line number. Itemindex+1>,itemindex starting from 0, so add 1 when using.
Repeater interlaced color, two ways