changing row color of datagrid on mouseover

Hello experts i have tried changing the row color of a datagrid on mouseover and mouse out and so far i can only get the text within the datagrid row to change, what am i doing wrong?

Here is how i get the text to change color.

 Private Sub dgpreview_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgpreview.ItemDataBound
        'handles the datagrid load
   
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            e.Item.Attributes.Add("onmouseover", "this.style.color='gold';")
            e.Item.Attributes.Add("onmouseout", "this.style.color='red';")
        End If


    End Sub

I tried doing this to get the back ground color of the row to change but it doesnt work.
 Private Sub dgpreview_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgpreview.ItemDataBound
        'handles the datagrid load
 
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            e.Item.Attributes.Add("onmouseover", "this.bgcolor='gold';")
            e.Item.Attributes.Add("onmouseout", "this.bgcolor='red';")
        End If


    End Sub
tentavariousAsked:
Who is Participating?
 
tewonderConnect With a Mentor Commented:
Hi!

bgcolor is html. What you're looking for is backgroundColor

For example:
this.style.backgroundColor='#ff0000'

That should to the trick.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.