.NET 2.0 Repeater - Different template for first item
I've got just another little trick with repeater control for you. Have you ever needed more complex rules for rendering ASP.NET 2.0 Repeater items not just ItemTemplate and AlternatingItemTemplate templates? For example different style/layout for the first item?
There is one really simple solution how to declaratively achieve such behavior. Simply define multiple placeholders and show/hide them according to data Container's ItemIndex property. The following example shows how to check for first repeater item...
1: <asp:Repeater runat="server">
2: <ItemTemplate>
3: <asp:PlaceHolder runat="server" Visible="<%# (Container.ItemIndex == 0) %>" >
4: </asp:PlaceHolder>
5: </ItemTemplate>
6: </asp:Repeater>