鼠标滑过GridView的数据行时修改行的背景颜色

基本原理可以参考另一篇文章:鼠标滑过table时修改表格行的背景颜色

下面是针对GridView实现该效果的代码:就是编写GridView控件的RowDataBound事件的代码。

 1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 2     {
 3         //首先判断是否是数据行
 4         if (e.Row.RowType == DataControlRowType.DataRow)
 5         {
 6             //当鼠标停留时更改背景色
 7             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#87CEEB'"); //#C4E1FF
 8             //当鼠标移开时还原背景色
 9             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
10         }
11     }
原文地址:https://www.cnblogs.com/huashanqingzhu/p/8884407.html