private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType==ListItemType.Item)||(e.Item.ItemType==ListItemType.AlternatingItem))
{
e.Item.Attributes.Add("onmouseover","c=this.style.backgroudColor;this.style.backgroudColor='#6699ff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroudColor=c");
}
}

解决方案 »

  1.   

    鼠标移来移去都一个颜色阿 当然看不出效果
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
    e.Item.Cells[2].Attributes.Add("onmouseover","this.style.backgroundColor='#6699ff'");
    e.Item.Cells[2].Attributes.Add("onmouseout","this.style.backgroundColor='原来的颜色'");
    }
      

  2.   

    this.style.backgroudColor=c,程序不能这样写的吧?
      

  3.   

    backgroudColor
    错误在于上面的单词中少了一个n
    backgroundColor
    还有像楼上所说的把颜色改成大红大绿的更能方便测试
      

  4.   

    For reference:
    .cs
         <script language="javascript">
    var c ;
    function backcol1(obj){
    bg = obj.style.backgroundColor;
    obj.style.backgroundColor='#6699ff';
    }
    function backcol2(obj){
    obj.style.backgroundColor=c;
    }
          </script>
    .aspx
          if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {            e.Item.Attributes.Add("onmouseover","javascript:backcol1(this)"); 
               e.Item.Attributes.Add("onmouseout","javascript:backcol2(this)"); 
    }
      

  5.   

    sorry 
    bg = obj.style.backgroundColor;
    bg->c
      

  6.   

    heyidan(gopee):
    “backgroudColor
    错误在于上面的单词中少了一个n”
    我没有少“n”啊!johnny1983():
    我没有设置同一色啊。
    我只是设置c变量保存原有的背景色c=this.style.backgroudColor,再把背景色设置成#6699ff,this.style.backgroudColor='#6699ff'。
    等鼠标离开时,恢复原有的色彩....
      

  7.   

    heyidan(gopee):
    “backgroudColor
    错误在于上面的单词中少了一个n”
    我没有少“n”啊!
    ---------------------------------------------------------------
    你的backgroudColor确实少了‘n’了,还不承认
    应该是backgroundColor