DataGrid和GridView鼠标移动上面背景变色

GridView鼠标移动背景变色,在RowDataBound事件中添加如下代码:

   protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "javascript:c=this.style.backgroundColor;this.style.background='#B0E0E6';");
            e.Row.Attributes.Add("onmouseout", "javascript:this.style.background=c;");
        }
    }

DataGrid鼠标移动背景变色,在ItemDataBound中添加如下代码

    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            e.Item.Attributes["onMouseOver"] = "javascript:c=this.style.backgroundColor;this.style.background='#B0E0E6';";  //current 粉蓝色 //--#6699ff 蓝色 #FFFF00 黄色 #FFFFE0 亮黄色
            e.Item.Attributes["onMouseOut"] = "javascript:this.style.background=c;";
        }
    }
原文地址:https://www.cnblogs.com/52net/p/2521329.html