Author: <a href="http://weblogs.asp.net/bleroy">Tales from the Evil Empire</a> : ASP.NET | Posted on: 7/23/2008 11:26:00 AM | Views : 850

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) ...

Go to the complete details ...