在DataGrid的ItemCreated事件里:Alternating_Color(e,"DataGrid1","#99CCFF");
public void Alternating_Color(System.Web.UI.WebControls.DataGridItemEventArgs MyE,string MyId,string MyColor)
{
//使DataGrid的行在鼠标滚动过的时候可以交替变色
if(MyE.Item.ItemType == ListItemType.Item || MyE.Item.ItemType == ListItemType.AlternatingItem)
{
//加入鼠标进出行时变色的脚本
MyE.Item.Attributes.Add("onmouseover","document.getElementById('" + MyId + "').oldValue = (this.style.backgroundColor==null)?'':this.style.backgroundColor;this.style.backgroundColor='" + MyColor + "';");
MyE.Item.Attributes.Add("onmouseout","this.style.backgroundColor=document.getElementById('" + MyId + "').oldValue;");
}
}