ASP.Net - ListVIew - AlternateColorOnEachRow

This is done with a modification to the ItemTemplate

1
2
3
4
<ItemTemplate> 
<tr class='ListViewRow&lt;%# Container.DataItemIndex Mod 2 %>' >
<td>
<asp:ImageButton ...

DataItemIndex returns a row number.

Mod 2 divides the row number down returning a value of 0 or 1.

Consequently you need 2 style sheets “ListViewRow0” and “ListViewRow1”

Here’s an example

1
2
3
4
5
6
7
8
9
.ListViewRow1{  
background-color: #F7F6F3;
color: #333333;
}

.ListViewRow0{
background-color: #FFFFFF;
color: #284775;
}