用css控制是王道!
在页面上的<body >里面加上onmouseover事件的处理函数就可以了。因为你不可能将你系统里所有的datagrid都加这些代码吧

解决方案 »

  1.   

    事件加错了,应该是rowbound事件里
      

  2.   

    tr里好像是没有效果的样。你放在td里看看呢?
      

  3.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataKey key = GridView1.DataKeys[e.Row.RowIndex];
                //鼠标经过时,行背景色变 
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
                //鼠标移出时,行背景色变 
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
                Image img = (Image)e.Row.Cells[1].FindControl("Image1");
                if (key["Lock_Man"].ToString() == string.Empty)
                {
                    img.ImageUrl = "~/images/unlock.gif";
                    img.ToolTip = "未保护";
                }
                else
                {
                    img.ImageUrl = "~/images/lock.gif";
                    img.ToolTip = "已保护";
                }
            }
        }
      

  4.   

    for(int i=0;i<e.Row.Cells.Count;i++)
    {
    e.Row.Cells[i].Attributes.Add("onmouseover","this.style.backgroudColor='#5D7C21';");
    e.Row.Cells[i].Attributes.Add("onmouseout","this.style.backgroudColor='#D91A01';");
    }
    这样加是加到tr上面
    改变tr的样式看不出来的