highlight row on mouseover

T

TJS

trying to use this code for mouseover highlight of row but it is not working
on the datagrid
can anyone tell me what is missing ?

Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
'---------------------------------------------------
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
End If

End Sub
 
A

Alexander Stojakovic

It will possibly affect performance positivly if you would handle the
Mouse_Over effects
on the client in JavaScript. I don't think it is a good idea to do a
postback on every mouse
move,

best regards

Sascha
 
A

Alvin Bruney [MVP]

It's not getting added per postback. The databound adds the javascript per
row being bound. I think this is too late. Move the code as is to the
itemcreated event handler, it should work there.
 
R

Renato Aloi

that's it! good tip. I've tried and the code is:

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated

If e.Item.ItemType = ListItemType.Item Then

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

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

ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then

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

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

End If

End Sub



[]s

Graccs





Alvin Bruney said:
It's not getting added per postback. The databound adds the javascript per
row being bound. I think this is too late. Move the code as is to the
itemcreated event handler, it should work there.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Alexander Stojakovic said:
It will possibly affect performance positivly if you would handle the
Mouse_Over effects
on the client in JavaScript. I don't think it is a good idea to do a
postback on every mouse
move,

best regards

Sascha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top