当前位置:Gxlcms > asp.net > asp.net Gridview数据列中实现鼠标悬浮变色

asp.net Gridview数据列中实现鼠标悬浮变色

时间:2021-07-01 10:21:17 帮助过:16人阅读

功能描述:
在gridview中,鼠标在这个控件的数据列表中移动时,该列的背景随鼠标的移动而改变背景颜色。
功能实现:
在gridview中新增一个事件RowDataBound,代码如下:
代码如下:
  1. <br>protected void gvwNews_RowDataBound(object sender, GridViewRowEventArgs e) <br>{ <br>if (e.Row.RowType == DataControlRowType.DataRow) <br>{ <br>e.Row.Attributes.Add("onmouseover", "color = this.style.backgroundColor;this.style.backgroundColor='#EAFCD5'"); <br>e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color"); <br>e.Row.Attributes.Add("onclick", "ClickRow()"); <br>} <br>} <br> <br>其中的onclick事件是控制选择行首的复选框的,点击行便实现"点击"复选框一样的效果。代码如下: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>function ClickRow() <br>{ <br>var obj = event.srcElement.parentElement.firstChild.firstChild.tagName; <br>alert(obj); <br>if(obj!=null && obj.tagName+""!="undefined") <br>{ <br>obj.checked=obj.checked ? false : true; <br>} <br>} <br> <br>简单的几行代码所需功能就可以实现了。</li><li> </li><li> </li></ol></pre>

人气教程排行