在DataGrid中实现鼠标指定列特殊显示的代码,VB.NET 2003

在DataGrid中的ItemDataBound事件中加入以下代码即可实现鼠标指定列的特殊显示,当鼠标移到DataGrid中一条数据时,该条数据以特殊颜色显示,当鼠标移开时,该条数据又以另外一种特殊颜色显示。

If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then

e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4EDF9'")

e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F1F3F5'")

End If