Вы можете использовать jQuery, чтобы решить эту проблему. Обратите внимание, что при этом вам необходимо добавить сценарий jQuery. Если у вас его еще нет, вы можете загрузить его из NuGet, если используете Visual Studio.
HTML КОД:
<div>
<table>
<tr>
<td>Even</td>
</tr>
<tr>
<td>Odd
</td>
</tr>
<tr>
<td>Even</td>
</tr>
<tr>
<td>Odd</td>
</tr>
<tr>
<td>Even</td>
</tr>
</table>
</div>
THE CSS:
.zebra {
background-color: blue;
color: white;
}
.zebra1 {
background-color: red;
color: white;
}
THE JAVASCRIPT:
<script src="Scripts/jquery-2.0.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("tr:even").addClass("zebra1"); //This code makes gives all even rows in the table the class of zebra1
$("tr:odd").addClass("zebra"); //This code makes all the odd rows in the table the class of zebra
});
Этот jQuery делает прикрепленные классы зебры и зебры1 к нечетным и четным строкам таблицы соответственно.