【问题标题】:hovering over gridview row overrides alternating row style悬停在 gridview 行上会覆盖交替行样式
【发布时间】:2011-02-17 01:30:24
【问题描述】:

下面是可以正常工作的代码,但我唯一的问题是:用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;");
}

【问题讨论】:

    标签: asp.net gridview


    【解决方案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');");
    

    【讨论】:

    • 抱歉,咖啡还不够。我混淆了一些引用。我认为上面的代码应该可以工作。这是一个工作示例jsfiddle.net/chprpipr/JqDda/3
    • 没有任何效果,它什么都不做。
    • 我已经删除了匿名函数调用,这似乎是绊脚石。我的工作示例中的蓝色行对您有用吗?
    • 我已经更新了你的新代码,它的行为有点古怪,我有一排白色 bgcolor 和替代颜色是 "#DEEEE9,当我将鼠标悬停在白色 bgcolor 行上时,我的 bgcolor 变为 #C2D69B如果我将鼠标悬停在替代行上,那么它工作正常。
    • 以上答案并没有解决我的问题,但为了它而关闭了这个问题
    猜你喜欢
    • 2021-09-02
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    相关资源
    最近更新 更多