The ASP.NET ListView control like most databound ASP.NET controls has an AlternatingItemTemplate which you can use for example to render different css class for odd and even rows. The control also has GroupTemplate which you can use to group items and display for example 3 items in TDs that are grouped in a TR. However there is no alternating group template. My question is how to alternate the class attribute of a tr in a GroupTemplate. Basically I want to have 3 items in a TR and alternating styles on odd and even TRs.
I want to avoid nesting one databound control in another and I've already tried binding the class of the TR in a databinding expression <%# Alternate() %>
but it seems that databinding expressions are only called in the itemtemplate (obviously they are used in the databind event and it is not called for the group template)
Any ideas?
Example code:
<asp:ListView ID="lv1" runat="server" EnableViewState="false" GroupItemCount="3">
<LayoutTemplate>
<table class="asd">
<asp:PlaceHolder ID="groupPlaceholder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr class='<%# GetAlternatingCssClass() %>'>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'> <%# Eval("Text") %> </asp:HyperLink>
</td>
</ItemTemplate>
</asp:ListView>