我写的一个关于变色的例子,供参考:
if (e.Item.ItemIndex != -1)
{
e.Item.Attributes.Add("onmouseover", "this.bgColor='#fafad2'");
if (e.Item.ItemIndex % 2 == 0 )
{
e.Item.Attributes.Add("bgcolor", "#E7E7FF");
e.Item.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('dgrdPfcx').singleValue");
}
else
{
e.Item.Attributes.Add("bgcolor", "#F7F7F7");
e.Item.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('dgrdPfcx').oldValue");
}
}
else
{
dgrdPfcx.Attributes.Add("oldValue", "#F7F7F7");
dgrdPfcx.Attributes.Add("singleValue", "#E7E7FF");   
}

解决方案 »

  1.   

    用样式//html中<style type="text/css">
    .normal { }
    .up { BACKGROUND-COLOR: #92d0df }
    </style>.cs中e.item.Attributes("onMouseOver")="this.className='up'"
    e.item.Attributes("onMouseOut")="this.className='normal'"
      

  2.   

    private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    //创建项时发生
    if(e.Item.ItemType!=ListItemType.Header&& e.Item.ItemType!=ListItemType.Pager) 
    { if(e.Item.ItemType!=ListItemType.AlternatingItem)
    {
    e.Item.Attributes["onmouseout"]="javascript:this.style.backgroundColor='#E7E7FF';";
    e.Item.Attributes["onmouseover"]="javascript:this.style.backgroundColor='#99cccc';";
    }
    else
    {
    e.Item.Attributes["onmouseout"]="javascript:this.style.backgroundColor='#F7F7F7';";
    e.Item.Attributes["onmouseover"]="javascript:this.style.backgroundColor='#99cccc';";
    }

    }

    }