在数据网格中显示备用行颜色

myn*_*neo 1 c# asp.net-mvc-3

有人可以帮助快速替代jquery显示具有不同背景颜色的备用行吗?尝试使用foreach循环但没有太多运气.非常感谢!!!

    <div class="acgridhdrstart">Account Name</div>
<div class="acgridhdr">Account Region</div>
<div class="acgridhdr">Account Representative</div>
<div class="acgridhdr">Peer Partner</div>
<div class="acgridhdr">Last Updated</div>
@while (myreader.Read())
{
<div class="bgcol">
 <span class="acgridstart">@myreader["acname"]</span>
 <span class="acgrid">@myreader["acregion"]</span>
 <span class="acgrid">@myreader["acrep"]</span>
 <span class="acgrid">@myreader["acpeer"]</span>
 <span class="acgrid">@myreader["lastupdated"]</span>
</div>
}
Run Code Online (Sandbox Code Playgroud)

Jam*_*ing 5

使用CSS3你可以:nth-​​child(偶数)和:nth-​​child(odd)

http://www.w3.org/TR/css3-selectors/#nth-child-pseudo

jQuery版本,FWIW:

http://api.jquery.com/nth-child-selector/

如果你想在视图代码中使用它,那么Phil Haack的Cycle方法可能会很有用

http://haacked.com/archive/2008/08/07/aspnetmvc_cycle.aspx

如果你不了解它,WebGrid有rowStyle和alternatingRowStyle

http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

http://msdn.microsoft.com/en-us/library/system.web.helpers.webgrid.gethtml(v=vs.99).aspx