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.
[sourcecode language=”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>
[/sourcecode]
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.
[sourcecode language=”vb”]
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
[/sourcecode]
Thanks to Rick for his orignal work.
http://www.west-wind.com/weblog/posts/2007/Aug/23/Creating-a-scrollable-and-grouped-Repeater-Layout