A neat solution to allow group headers on repeaters without using much code or nested repeaters. Rick Strahl provides a good example of this stragegy in C# i have modifid this slightly and converted to VB.
<asp:Repeater ID="RPContent" runat="server"> <ItemTemplate> <%# Me.RenderGroup(Eval("theyear")) %> <div class="headline"> <h3><a href="<%# Eval("url ")%>"><%# Eval("description") %></a></h3> <p><%# Eval("thedatestr")%></p> </div> </ItemTemplate> </asp:Repeater>
Whilst the last closing div may look out of place it is required to close the last repeater item. the eval RenderGroup function passes the vasriable that you wish to group the repeater by. This function then returns a header div if the item in the repeater is part a new group or nothing if the next item in the repeater matches the same group as the preivous one.
I’ve added the active class to the div for the first group to be selected automaticaly with the jquery paging plugin this then pages the repeater list based on the group.
Public LastGroup As String = "@#@~" Public Function RenderGroup(Group As String) As String If (Group = Me.LastGroup) Then Return "" Else '// *** Group has changed If LastGroup = "@#@~" Then 'start group Me.LastGroup = Group Return "<div id='pane" + Group + "' class='tab-pane active'>" Else Me.LastGroup = Group Return "</div><div id='pane" + Group + "' class='tab-pane'>" End If End If End Function
Thanks to Rick for his orignal work.