如何在GridView控件中实现光棒效果?

如何在GridView控件中实现光棒效果?

在GridView1_RowDataBound事件中添加如下代码:

if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "before=this.style.backgroundColor;this.style.backgroundColor='gray'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=before");
            }
  • onmouseover:鼠标移入事件

    • before=this.style.backgroundColor;this.style.backgroundColor='gray'

      解释:先获取当前鼠标移入的背景颜色,在设置当前背景颜色

  • onmouseout:鼠标移出事件

    • this.style.backgroundColor=before

      解释:将该背景颜色还原

每个人都是在努力的路上,别因为别人的误解而放弃,,术业有专攻,如是而已。
原文地址:https://www.cnblogs.com/16699qq/p/13361178.html