ASP.NET ListView Alternating Groups
<p>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.</p>

<p>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 <code>&lt;%# Alternate() %&gt;</code> 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)</p>

<p>Any ideas?</p>

<p>Example code:</p>

<pre><code>    &lt;asp:ListView ID="lv1" runat="server" EnableViewState="false" GroupItemCount="3"&gt;
    &lt;LayoutTemplate&gt;
        &lt;table class="asd"&gt;
            &lt;asp:PlaceHolder ID="groupPlaceholder" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
        &lt;/table&gt;
    &lt;/LayoutTemplate&gt;
    &lt;GroupTemplate&gt;
        &lt;tr class='&lt;%# GetAlternatingCssClass() %&gt;'&gt;
            &lt;asp:PlaceHolder ID="itemPlaceholder" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
        &lt;/tr&gt;
    &lt;/GroupTemplate&gt;
    &lt;ItemTemplate&gt;
        &lt;td&gt;
            &lt;asp:HyperLink runat="server" NavigateUrl='&lt;%# Eval("Url") %&gt;'&gt; &lt;%# Eval("Text") %&gt; &lt;/asp:HyperLink&gt;
        &lt;/td&gt;
    &lt;/ItemTemplate&gt;
&lt;/asp:ListView&gt;
</code></pre>
