Alternating styles in ListView without AlternatingItemTemplate
ListView (the server-side control), like all repeating data controls in ASP.NET, has an AlternatingItemTemplate , but it would be a shame to have to copy all the markup in the ItemTemplate into AlternatingItemTemplate , just to alternate styles on the items. It's quite likely that only css classes will change between the two, and redundancy is bad <- big scoop here. But there is a simpler way. From within any template, you have access to the current index of the row within the whole data set, using Container.DataItemIndex , and within the currently displayed items, using Container.DisplayIndex . This gives us an easy way to alternate styles: < ItemTemplate > < li class =" <% # Container.DisplayIndex % 2 == 0 ? "even"
Read More...
Read the complete post at http://weblogs.asp.net/bleroy/archive/2008/07/23/alternating-styles-in-listview-without-alternatingitemtemplate.aspx