Highlighting DataGrid Rows on mouseOver

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need to extend functionality of ASP.NET datagrid. Onmouse over, the whole
row needs to be highlighted. OnClick highlighted color must remain, and the
value of one of the columns must be set to innerHTML property of a <div> tag
(no postBack).
Has anyone done anything like that?
 
Yep try using ItemCreated like below:-

Sub MenuGrid_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles MenuGrid.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem
Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='beige';this.style.cursor='hand'")
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='white';")
End If
End Sub

Hope it helps!!
Patrick
 
Thanks for the prompt reply. I think yoiur code will work for highlighting.
One more question; in this ItemCreated event, can I access a value of a
specific column?
Thank you!
 
Yes WebMatrix..
For example by doing (For the first Cell!!):-

e.Item.Cells(1).Attributes.Add("onmouseover",
"this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout",
"this.style.backgroundColor='white'")

Enjoy
Patrick
 
If it is a bound column, the value will become known in ItemDataBound event.
You can move all this code over there.

Eliyahu
 

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

Back
Top