views:

87

answers:

1

Need to add styles (class="bBot") to the first ItemTemplate item, how do I know it's the first?

<asp:Repeater id="ArticlesRepeater" runat="server">
    <HeaderTemplate>
        <div class="FR boxW380">
            <div class="cnt mag">
             <div class="FR">
                    <a href="#">Subscribe</a>
                    &#160; &#160;
                    <a href="#">Archive</a>
             </div>
             <h1>Magazine</h1>
    </HeaderTemplate>

    <ItemTemplate>
                <div>
                    <a href="#">
                        <img class="visu" alt=""
                            src="<%# DataBinder.Eval(Container.DataItem, "image") %> " />
                        <span class="title">
                            <%# DataBinder.Eval(Container.DataItem, "title") %>
                        </span>
                        <span class="content">
                            <%# DataBinder.Eval(Container.DataItem, "shortintroduction")%>
                        </span>
                    </a>
                    <div class="CB"></div>
                </div>
    </ItemTemplate>

    <FooterTemplate>
            </div>
        </div>
    </FooterTemplate>
</asp:Repeater>
+1  A: 
((Panel) ArticlesRepeater.Items[0].Controls[0]).CssClass = "bBot";

This will give you a reference to the first control contained in the first item in the repeater's Item collection. You would still need to cast this control to the appropriate type. In your example, assuming you wish to apply the css to the containing div, change it to a Panel (server control) to make casting simpler and set the CssClass property.

HectorMac