GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

Last post 09-28-2009 12:43 PM by cruncher06. 6 replies.

Sort Posts:

  • GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    12-08-2005, 6:17 AM
    • Member
      15 point Member
    • Waffel
    • Member since 12-08-2005, 11:09 AM
    • Posts 3

    hi from germany,
    i've tried out to setup a gridview (asp.net 2.0) with mouseover/out and i only found the examples with itemdatabound! but itemdatabound for gridview is no longer available in asp.net 2.0!

    here is a solution which woks fine...

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

    If Not e.Row.RowType = DataControlRowType.Footer _
       And Not e.Row.RowType = DataControlRowType.Header _
       And Not e.Row.RowType = DataControlRowType.Pager Then
       
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E48484';this.style.color='#FFFFFF';")
    End If

    If Not e.Row.RowType = DataControlRowType.Footer _
       
    And Not e.Row.RowType = DataControlRowType.Header _
       
    And Not e.Row.RowType = DataControlRowType.Pager Then
       
    If e.Row.RowState = DataControlRowState.Normal Then
          
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';this.style.color='';")
       
    ElseIf e.Row.RowState = DataControlRowState.Alternate Then
          
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F5F5F5';this.style.color='';")
       
    End If
    End If

    End Sub

  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    12-08-2005, 3:29 PM
    • Contributor
      3,783 point Contributor
    • datagridgirl
    • Member since 06-11-2002, 2:39 AM
    • Atlanta, GA
    • Posts 747
    • ASPInsiders

    There are no "Items" in the ASP.NET 2.0 GridView, the concept of item has been renamed "Row".  So e.Item becomes e.Row, and ItemDataBound goes to RowDataBound.

    Hope that helps.

    Marcie

  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    12-09-2005, 2:35 AM
    • Member
      15 point Member
    • Waffel
    • Member since 12-08-2005, 11:09 AM
    • Posts 3

    Hi datagridgirl,

    you're right.

    the reason for my posting was that i was not able to find a quick solution in the web.
    after a long time of "try and error" (i'm new to asp.net 2.0) i created this solution...

    greetings from germany

    waffel

  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    01-13-2006, 1:20 PM
    • Member
      5 point Member
    • vujadin
    • Member since 01-13-2006, 6:18 PM
    • Posts 1

    Thanks, thanks and thanks to both of you...

    This solved my issue.

  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    04-22-2007, 9:44 PM
    • Member
      2 point Member
    • Anastacio Ham
    • Member since 04-23-2007, 1:35 AM
    • Posts 1

    En este GridView tengo diferentes colores para los renglones los cuales asigno segun el estatus (campo de una tabla de una
    base de datos) a la vez agrego el atributo onmouseover para que al pasar el mouse cambie el color a todos los renglones,
    y el atributo onmouseout para que me deje los distintos colores que tenian los renglones antes de pasar el mouse sobre ellos:
       
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Brown'; this.style.color='White'; this.style.cursor='pointer';")
                Select Case DataBinder.Eval(e.Row.DataItem, "estatus")
                    Case "1"
                        e.Row.BackColor = Drawing.Color.FromName("#ffff99")
                        e.Row.ForeColor = Drawing.Color.Black
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffff99'; this.style.color='#333333';")
                    Case "2"
                        e.Row.BackColor = Drawing.Color.FromName("#f4de41")
                        e.Row.ForeColor = Drawing.Color.Black
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#f4de41'; this.style.color='Black';")
                    Case "3"
                        e.Row.BackColor = Drawing.Color.Gold
                        e.Row.ForeColor = Drawing.Color.Black
                        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='Gold'; this.style.color='Black';")
                    Case "4"
                        e.Row.BackColor = Drawing.Color.FromName("#f8b84d")
                        e.Row.ForeColor = Drawing.Color.Black
                    End Select
            End If
    End Sub

     Saludos Yes

  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    05-03-2007, 7:44 PM
    • Member
      336 point Member
    • jsearles
    • Member since 08-02-2006, 6:54 AM
    • Posts 89
    This all works fine, but i have found using CSS works better. You can use a class to assign a style for the row, and then use :hover to assign the class for that row when it is hovered over. For example:

    TR { background-color: white; }
    TR:hover { background-color: gray; }

    The only catch to this is IE6 does not recognise the "hover" attribute for links only. To get around this, i've loaded a fix to my style sheets like the one in the following link. Works great and renders cleaner HTML.

    http://www.xs4all.nl/~peterned/csshover.html
  • Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound

    09-28-2009, 12:43 PM
    • Member
      4 point Member
    • cruncher06
    • Member since 03-28-2008, 10:57 AM
    • Posts 2

     Waffel,

    This was quite helpful. It has helped me with a question that I have, but now don't have to post. Thank you for your post.

     

    Chris S.

Page 1 of 1 (7 items)