protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //判断是否是DataRow,以防止鼠标经过Header也有效果
{
e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor; this.style.backgroundColor='#cccccc'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow) //判断是否是DataRow,以防止鼠标经过Header也有效果
{
e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor; this.style.backgroundColor='#cccccc'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");
}
}
本文介绍如何使用ASP.NET中的GridView控件实现当鼠标悬停在数据行上时改变背景颜色的效果。通过在GridView_RowDataBound事件中添加JavaScript代码实现交互功能。
1315

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



