//方法1 后台代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFDD7'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
方法2,前台代码
<tr onclick="test(this)" style="cursor: pointer" onmouseover="currentBgColor=this.style.backgroundColor;this.style.backgroundColor='#cccfff';"
onmouseout="this.style.backgroundColor=currentBgColor">

本文介绍两种实现网格视图中鼠标悬停时改变行背景颜色的方法:一种是在后台使用C#进行处理,另一种是在前台通过HTML和JavaScript实现。这两种方法均可用于改善用户体验,使用户能够更直观地看到当前鼠标所在位置。
3544

被折叠的 条评论
为什么被折叠?



