.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>
I realize this is well after you've posted this solution, but I faced a similar problem and after some tedious searching, including finding several suggestions that one should completely rewrite the Repeater control, which is a bit more work than I could justify spending time on, I found your post here, and I must say that this is a simple and brilliant solution to my problem, thanks for your post!!