OnMouseOver for a DataGrid control

G

Guest

Hi,

I want to create a client-side script
that highlights a row of a datagrid control
when the mouse cursor is over that row (i.e.
chage the color of the row to something else
than the current color), but apparently the
datagrid doesn't have an OnMouseOver event.
It works with regular html tables but not with
the datagrid control. is there a way to do it?

Thanks
 
G

Guest

Nope :)
I'm totally new to asp.net and
its controls. I didn't even know
that the datagrid had an attributes
property (it is a property, right?)

Thanks for any help you give, guys
 
G

Guest

I still can't figure out how to do that.
Sorry for my ignorance.
Can anyone please help me?
 
G

Greg Burns

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

If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor
= 'lightgreen';")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor
= 'white';")

End If

End Sub

HTH,
Greg
 
M

Mr. Dot Net

You have few steps before you can achieve that:
First, write down a js function that retrieves 2 args: tr & color and change
the tr bgcolor according to the parameters: this is done by iterating over
all it's cells.
Second, write event handler for the ondatagriditemcreated of the datagrid
control you meant to enable this feature. In that event handler add 2
attributes for each datagriditem (not including footer, header etc.). These
2 attributes will be onmouseover and onmouseout. In it write a simple code
that will use the above js function to change the tr color (each
datagriditem is actually a TR).
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top