如何让鼠标经过datagrid的一行时(表头不算)那一行的颜色变成其它颜色呢?
datagrid中没有table,是动态生成的

解决方案 »

  1.   

    private void priceadmingrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
    }
      

  2.   

    再ItemDataBound事件中给DateItem的项增加属性Attributes就好了
    private void priceadmingrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
    }
      

  3.   

    private void dg_ItemDataBound(object sender, DataGridItemEventArgs e) 
      { 
       if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
       { 
     //颜色交替   
        e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'"); 
        if(e.Item.ItemType == ListItemType.Item) 
        { 
         e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'"); 
        }     if(e.Item.ItemType ==ListItemType.AlternatingItem) 
        { 
         e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='seashell'"); 
        } 
       } 
      }
      

  4.   

    private void dg_ItemDataBound(object sender, DataGridItemEventArgs e) 
      { 
       if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
       { 
         e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'");  
         e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'"); 
       } 
      }
      

  5.   

    private void changeRowColor(object sender,ystem.Web.UI.WebControls.DataGridItemEventArgs e)
    {
      //如果是数据项并且是交替项
    if(e.Item.ItemType == ListItemType.Item  || e.Item.ItemType ==ListItemType.AlternatingItem)
    {
    //添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
    e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
    //添加自定义属性,当鼠标移走时还原该行的背景色
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor"); } 
    }
      

  6.   

    浪子的是对的,我也是这么做---------------
    欢迊来到麦高网-私活兼职首选平台 www.mgao.net
      

  7.   

    http://goody9807.611.cn/Announce/Announce.asp?BoardID=2&ID=1139