highlight row on mouseover

Discussion in 'ASP .Net Datagrid Control' started by TJS, Feb 17, 2004.

  1. TJS

    TJS Guest

    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
     
    TJS, Feb 17, 2004
    #1
    1. Advertising

  2. 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
    "TJS" <> wrote in message
    news:eaI$...
    > 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
    >
    >
     
    Alexander Stojakovic, Feb 17, 2004
    #2
    1. Advertising

  3. 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" <> wrote in
    message news:...
    > 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
    > "TJS" <> wrote in message
    > news:eaI$...
    > > 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
    > >
    > >

    >
    >
     
    Alvin Bruney [MVP], Feb 17, 2004
    #3
  4. TJS

    Renato Aloi Guest

    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 [MVP]" <vapor at steaming post office> escreveu na mensagem
    news:%...
    > 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" <> wrote in
    > message news:...
    > > 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
    > > "TJS" <> wrote in message
    > > news:eaI$...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Renato Aloi, Feb 17, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TJS
    Replies:
    1
    Views:
    3,341
    =?Utf-8?B?QW5hbmQgTW9oYW4=?=
    Feb 17, 2004
  2. =?Utf-8?B?YmFjazJncmlk?=

    highlight datagrid row on radiobutton selection

    =?Utf-8?B?YmFjazJncmlk?=, Sep 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    489
    =?Utf-8?B?YmFjazJncmlk?=
    Sep 13, 2004
  3. Fernando Lopes
    Replies:
    0
    Views:
    3,214
    Fernando Lopes
    Apr 28, 2005
  4. kaston3
    Replies:
    1
    Views:
    576
    Andrew Bailey
    Feb 19, 2008
  5. D
    Replies:
    0
    Views:
    257
Loading...

Share This Page