求助,DataGrid中实现鼠标移到某一行时该行颜色改变时遇到的问题

来源:互联网 发布:韩子高网络剧百度云 编辑:程序博客网 时间:2024/05/01 17:24

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

代码没有问题,Attributes是不是用来增加属性的?

运行后没有反应.

原创粉丝点击