//html 代码 <asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<table cellpadding=0px cellspacing=0px>
//把tr转化为服务器控件
<tr runat="server" id="r1"><td><%#DataBinder.Eval(Container.DataItem,"AccountID") %></td><td><%#DataBinder.Eval(Container.DataItem,"AccountCode") %></td></tr>
</table>
</ItemTemplate>
</asp:Repeater>
//.cs代码
protected void Page_Load(object sender, EventArgs e)
{
//绑定数据源
Repeater1.DataSource = GridViewClass.ReadData();
Repeater1.DataBind();
}
//数据行绑定时判断数据来改变行的背景颜色
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
string AccountCode = ((DataRowView)e.Item.DataItem).Row["AccountCode"].ToString();
if (AccountCode.Trim() == "3000B020")
{
HtmlTableRow col = (HtmlTableRow)e.Item.FindControl("r1");
col.BgColor = "#889998";
}
}
//以上代码希望对你有所帮助
用css来控制
tr:nth-child(even) td{background-color:red}
<script src="JS/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//实现斑马线效果
$("tr:even").css("backgroundColor", "#e7e7ff");
$("tr:odd").css("backgroundColor", "#f7f7f7");
//光棒效果
$("tbody tr").hover(function() {
$(this).css("backgroundColor", "gray");
},
function() {
$("tr:even").css("backgroundColor", "#e7e7ff");
$("tr:odd").css("backgroundColor", "#f7f7f7");
});
});
</script>
感觉还是直接使用CSS控制比较好