GridView:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");
e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor;this.style.backgroundColor=\"" + "#EFF3F7" + "\"");
}
}
DataList:
ItemTemplate模板列中把Table属性设置onmouseover和onmouseout,配合如下JS代码:
<script>
var classname = ""
function TbOnmouseover(val)
{
classname = val.className
val.className = "DataListSelecte"
}
function TbOnmouseout(val)
{
val.className = classname
}
</script>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)