你要 遍历 它的列
foreach(DataGrid item in grd.items){    然后
   for(int i=0;i<=grd.coloumns.count-1;i++)
    {
   e.Item.cells[i].Attributes.Add("onmouseover", "currentcolor=this. style.backgroundColor; this.style.backgroundColor = '#faf0e6' ");
    e.Item.cells[i].Attributes.Add("onmouseout", "this.style.backgroundColor = currentcolor");
   }
}

解决方案 »

  1.   

    在Item_Create中添加代码:
    #region DataGrid Item Create 
    public void DataGrid_ItemCreate(objectsender,System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
       if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
       {
        e.Item.Attributes.Add("onclick","javascript:return CG(this);");//单击改变颜色
       }
      }
      #endregion
    客户端代码:(javascript):
                      <script language=javascript>function CG(obj)
    {
    var Curr_TR=document.all.tags("tr");
    for(var i=1;i<Curr_TR.length;i++)
    {
    Curr_TR[i].Style.backgroundColor="white";
    }
    obj.style.backgroundColor="yellow";
    }
    </script>
      

  2.   

    if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("onmouseover","this.oldColor=style.backgroundColor;style.backgroundColor='#FFFFCC'");
    e.Item.Attributes.Add("onmouseout","style.backgroundColor=this.oldColor");
    }
      

  3.   

    后端代码:
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                e.Item.Attributes.Item("onclick") = "DoTrClick(this)"
            End If
    End Sub
    客户端代码:
    var lastObj,lastColor; 
    function doTrClick(objTr) {
     if(lastObj==undefined)
     { 
    lastObj = objTr; 

    lastObj.style.backgroundColor = lastColor; 
    lastObj = objTr; 
    lastColor=lastObj.style.backgroundColor;
     lastObj.style.backgroundColor = "#CFF3D5"; // 设置选中行背景色
    }
      

  4.   

    我正好刚解决了这个问题,贴出来帮楼主一下。
    前台JS代码
    function setItemBackColor(obj)
    {
        var Curr_TR=document.all.tags("tr");
        for(var i=1;i<Curr_TR.length;i++)
        {
            if (Curr_TR[i].style.backgroundColor =="yellow")
            {
                Curr_TR[i].style.backgroundColor="white";
            }
        }
        obj.style.backgroundColor="yellow";
    }
    后台C#代码
    private void dgDocClass_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    e.Item.Attributes.Add("onclick","return setItemBackColor(this)");
                }
            }
    马上结贴,得分啦!
      

  5.   

    //问题还是没有解决://1、在ItemDataBound事件中,下面的例子,在data grid上移动鼠标是有效的。e.Item.Attributes.Add("onmouseover", "setAttribute('attrb', style.backgroundColor); style.backgroundColor = '#f5f5f5' ");
    e.Item.Attributes.Add("onmouseout", "style.backgroundColor = getAttribute('attrb');");
    //2、但是下面的代码,单击鼠标可以实现更改。但并不能更改失去焦点的颜色。e.Item.Attributes.Add("onclick", "setAttribute('attrb', style.backgroundColor); style.backgroundColor = '#faf0e6' ");
    e.Item.Attributes.Add("onblur", "style.backgroundColor = getAttribute('attrb');");
      

  6.   

    e.Item.Attributes.Add("onactivate", "runtimeStyle.backgroundColor='#eeeeee'");
    e.Item.Attributes.Add("ondeactivate", "runtimeStyle.backgroundColor=''");
      

  7.   

    谢谢帮主,谢谢啦...(不过onblur为什么不行呢?)
      

  8.   

    Lostinet(『 迷失网络 』 MVP) 
    的办法好用!
      

  9.   

    一般的元素是没有blur的。
    有blur的一般是input,textarea,button,select等东西。