How can I create alternating background colors for listview rows while only using ItemTemplate? I don’t want to use AlternateTemplate because I would have to edit both of them everytime i want to change something when all I’m using it for is to create the alternating background colors. So what’s a way I could do it using only the ItemTemplate? Thanks!
How can I create alternating background colors for listview rows while only using ItemTemplate?
Share
If you could consider the alternating colours a progressive enhancement and not absolutely required in all (old) browsers then you could use a CSS n-th child selector to apply the colour without changing the HTML.
If you have jQuery (or similar) in your project already and want a solution for older browser, you could use that to select every other row with the :odd or :even selector.
Update (Example)
Assuming we are using table rows
You can also use
even,2nor2n+1. This would work equally well with<li>tags.More examples: http://reference.sitepoint.com/css/pseudoclass-nthchild