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
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.
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...
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
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:
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.
Waffel
Member
15 Points
3 Posts
GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Dec 08, 2005 10:17 AM|LINK
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
datagridgirl
Contributor
4417 Points
849 Posts
ASPInsiders
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Dec 08, 2005 07:29 PM|LINK
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
Waffel
Member
15 Points
3 Posts
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Dec 09, 2005 06:35 AM|LINK
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
vujadin
Member
5 Points
1 Post
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Jan 13, 2006 05:20 PM|LINK
Thanks, thanks and thanks to both of you...
This solved my issue.
Anastacio Ha...
Member
2 Points
1 Post
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Apr 23, 2007 01:44 AM|LINK
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]
jsearles
Member
337 Points
91 Posts
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
May 03, 2007 11:44 PM|LINK
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
cruncher06
Member
4 Points
3 Posts
Re: GridView and MouseOver with ASP.NET 2.0 - missing itemdatabound
Sep 28, 2009 04:43 PM|LINK
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.