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

时间:2023-03-09 19:39:18
GridView 鼠标经过时变色两种方法

第一种:

新建一个js文件 并引用

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

js文件内容如下:

 var _oldColor;
function SetNewColor(source)
{
_oldColor=source.style.backgroundColor; source.style.backgroundColor='#F0F7FD';
} function SetOldColor(source)
{
source.style.backgroundColor=_oldColor;
}

给GridView添加RowDataBound事件

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

 protected void DGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
}
}

第二种:

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