第一种:

 新建一个js文件 并引用

1  <script src="jquery.js" type="text/javascript"></script>

js文件内容如下:

 1 var _oldColor;      
 2 function SetNewColor(source)      
 3 {      
 4     _oldColor=source.style.backgroundColor;      
 5   
 6      source.style.backgroundColor='#F0F7FD';      
 7 }      
 8   
 9  function SetOldColor(source)      
10 {      
11     source.style.backgroundColor=_oldColor;      
12 }

给GridView添加RowDataBound事件

GridView 鼠标经过时变色两种方法

1 protected void DGV_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3   if (e.Row.RowType == DataControlRowType.DataRow)
4   {
5      e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
6      e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
7   }
8 }

 

第二种:

1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3         if (e.Row.RowType == DataControlRowType.DataRow)
4         {
5             //高亮显示指定行
6             e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
7             e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");   
8         }
9 }

 

相关文章:

  • 2021-09-11
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2021-09-09
  • 2022-01-09
相关资源
相似解决方案