{
if (e.Item.ItemType == ListItemType.Item)
{
if (e.Item.FindControl("itl") != null)
{
HtmlTableRow htr_itl = (HtmlTableRow)e.Item.FindControl("itl");
ApplyStyle(htr_itl, "#fff");
}
}
if (e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.FindControl("att") != null)
{
HtmlTableRow htr_att = (HtmlTableRow)e.Item.FindControl("att");
ApplyStyle(htr_att, "#E9F2FB");
}
}
}
private void ApplyStyle(HtmlTableRow htr, string trBackColor)
{
string onmouseoverStyle = "this.style.backgroundColor='#BCE774'";
string onmouseoutStyle = "this.style.backgroundColor='@BackColor'";
htr.Attributes.Add("onmouseover", onmouseoverStyle);
htr.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", trBackColor));
}
2.使用onmouseover/onmouseout
<div style=" line-height:20px;border-bottom: #fff 1px solid; background-color:#E9F2FB" id="att" runat="server" οnmοuseοver="tempBgColor=this.style.backgroundColor;this.style.backgroundColor='#BCE774';" οnmοuseοut="this.style.backgroundColor=tempBgColor" >
</div>