日期:2014-05-20  浏览次数:20890 次

ASPxGridView使用JavaScript实现行颜色改变
我实现下面的功能:
  当鼠标移动到ASPxGridView某行时,该行的背景颜色发生改变。、
  我想请教下,鼠标移动的js怎么写。怎么将写好的js用来实现功能(我是新手,望详细些)!

------解决方案--------------------
在 onmouseover, onmouseout 事件里面处理:
如下面的代码:
<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById('b1').src ="/i/eg_mouse.jpg"
}
function mouseOut()
{
document.getElementById('b1').src ="/i/eg_mouse2.jpg"
}
</script>
</head>

<body>
<a href="http://www.w3school.com.cn" 
onmouseover="mouseOver()" onmouseout="mouseOut()">
<img alt="Visit W3School!" src="/i/eg_mouse2.jpg" id="b1" />
</a>
</body>
</html>
------解决方案--------------------
也可以在后台CS文件里写
当然还要在前台的 gridview里设置事件RowDataBound方法为下面的方法
protected void userGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='lightBlue'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}

}