您的位置:首页 > 其它

Gridview鼠标移动到数据行时改变该数据行的背景色

2012-07-30 22:51 357 查看
方法一

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//设置鼠标覆盖时数据行的背景色

e.Row.Attributes.Add("onmouseover","this.style.backgroundColor='green'");

//设置鼠标离开该数据行时数据行的背景色,即还原数据行背景色

e.Row.Attributes.Add("onmouseout","this.style.background='#ffffff'");

//设置鼠标覆盖数据行时鼠标样式

e.Row.Attributes["style"] = "Cursor:pointer";

}

}

方法二:此方法的好处是不会修改原来的所有行背景色!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

//设置鼠标覆盖时数据行的背景色

e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor; this.style.backgroundColor='green'");

//设置鼠标离开该数据行时数据行的背景色,即还原数据行背景色

e.Row.Attributes.Add("onmouseout","this.style.background=c);

//设置鼠标覆盖数据行时鼠标样式

e.Row.Attributes["style"] = "Cursor:pointer";

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: