我试图在我的备用行上简单地添加一个 css 类到一个 div 中,<itemtemplate/>
而不需要包含一个完整的开销,<alternatingitemtemplate/>
这将迫使我在未来保持很多标记同步。
我已经看到了一个解决方案,例如我的http://blog.net-tutorials.com/2009/04/02/how-to-alternate-row-color-with-the-aspnet-repeater-control/很想使用,但这对我来说仍然没有“气味”。
还有其他人有更易于维护和直接的解决方案吗?理想情况下,我希望能够执行以下操作:
<asp:repeater id="repeaterOptions" runat="server">
<headertemplate>
<div class="divtable">
<h2>Other Options</h2>
</headertemplate>
<itemtemplate>
<div class="item <%# IsAlternatingRow ? "dark" : "light" %>">
但我无法弄清楚如何实现IsAlternatingRow
- 即使使用扩展方法。