.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...


< asp:Repeater runat="server">
< ItemTemplate>
< asp:PlaceHolder runat="server" Visible="<%# (Container.ItemIndex == 0) %>" >
</asp:PlaceHolder>
</ItemTemplate>
</asp:Repeater>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: