将鼠标悬停在gridview行上会覆盖交替的行样式

时间:2011-02-15 16:50:31

标签: asp.net gridview

下面的代码工作正常,但我唯一的问题是:用backgroundColor='white'覆盖备用行如何在onmouseout时如何使用我的替代颜色?

 <AlternatingRowStyle BackColor="#DEEEE9" Font-Size="8pt" />

if (e.Row.RowType == DataControlRowType.DataRow)
{
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
    e.Row.Attributes.Add("style", "cursor:pointer;");
}

1 个答案:

答案 0 :(得分:1)

虽然我不喜欢在代码隐藏中设置这些内容,但我认为这些内容会照顾你:

e.Row.Attributes.Add("onmouseover", "this.setAttribute('bgColor', this.style.backgroundColor); this.style.backgroundColor = '#C2D69B';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = this.getAttribute('bgColor');");
相关问题