OnMouseOver for a DataGrid control

Discussion in 'ASP .Net' started by Guest, Jul 12, 2004.

  1. Guest

    Guest 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
     
    Guest, Jul 12, 2004
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    have you tried

    datagrid1.attributes("onmouseover")="myjavafunction()"
     
    Guest, Jul 12, 2004
    #2
    1. Advertisements

  3. Guest

    Guest 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
     
    Guest, Jul 12, 2004
    #3
  4. Guest

    Guest Guest

    I still can't figure out how to do that.
    Sorry for my ignorance.
    Can anyone please help me?
     
    Guest, Jul 12, 2004
    #4
  5. Guest

    Greg Burns Guest

    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
     
    Greg Burns, Jul 12, 2004
    #5
  6. Guest

    Mr. Dot Net Guest

    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).
     
    Mr. Dot Net, Jul 12, 2004
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.