当鼠标点击 GridView 的某行时,该行换色,该怎么写呢

来源:百度知道 编辑:UC知道 时间:2024/06/24 16:52:25
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add( "onclick ", "showColor(this) ");
}

<script type= "text/javascript ">
function showColor(obj)
{
var rowindex = obj.rowIndex;
obj.style.backgroundColor= '#ff9900 ';
for(var i=1;i <obj.parentElement.rows.length;i++)
{
if(i!=rowindex)
{
obj.parentElement.rows[i].style.backgroundColor = "#ffffff ";
}
}
}
</script>

showColor(this)里面的this是什么意思,代表什么?
谢谢几位大师 我要的是鼠标点击事件 不是 鼠标经过事件 我试过了 因为这个是JS代码 所以 每当我点击这行的按钮时页面总是会回发 所以JS等于没执行 当我把按钮去的时候 再点击这行就有效果了 不过还有别的方式了吗?!

是对e.Row加的属性,this当然是指e.Row了
而e.Row会被解释成<tr></tr>
所以这个this就是这一行,也就是<tr>

protected void productclassGrdv_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//先设置当鼠标上去的时候他的背景色改变
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#e4ebf1'");
//再设置当鼠标离开后背景色再还原
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");

}
}