来自Asp.net精英论坛:bbs.1aspx.com
在GridView的
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
}
}
在页面中加入
<script language="javascript">
var _oldColor;
function SetNewColor(source)
{
_oldColor=source.style.backgroundColor;
source.style.backgroundColor='#666666';
}
function SetOldColor(source)
{
source.style.backgroundColor=_oldColor;
}
</script>

本文介绍如何使用ASP.NET中的GridView控件实现鼠标悬停时行背景颜色的变化效果。通过结合JavaScript函数SetNewColor和SetOldColor,在RowDataBound事件中为每行添加onMouseOver和onMouseOut属性,实现交互式视觉体验。

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



