I have a DataGrid and I want to change the background color of the whole row when I mouse over.
I tried using e.Item.Attributes["onmouseover"] = "this.style.color='red'";
but this only changes the color of the text in the row. I want to highlight the full row. How do I set the background color to change the row in the DataGrid in the code behind?
Private Sub DataGridID_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGridID.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
' Do the mouseover and mouseout javascript
Dim oBGcolour As String
If e.Item.ItemType = ListItemType.Item Then
oBGcolour = Right(Hex(DataGridID.ItemStyle.BackColor.ToArgb()), 6)
ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
oBGcolour = Right(Hex(DataGridID.AlternatingItemStyle.BackColor.ToArgb()), 6)
End If
e.Item.Attributes.Add("onmouseover", "this.style.background='#cdcdcd';")
e.Item.Attributes.Add("onmouseout", "this.style.background='#" & oBGcolour & "';")
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.