[RESOLVED] [2005] Gridview row color change on mouseover
I migrated this code from vs 03 to vs 05.
It work fine in 03 but not 05.
Quote:
note : the code below is 05 which is modified.
When I execute code below in my vs 05 the row color has changed but when mouseout from row the color will change back to only 1 type of color.
Can any one figure out my wrong ?
asp Code:
Protected Sub grdStatusMaster_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdStatusMaster.RowDataBound
If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Then
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='ghostwhite'")
If e.Row.RowType = ListItemType.Item Then
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='WhiteSmoke'")
Else
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White'")
End If
End If
End Sub
Re: [2005] Gridview row color change on mouseover
You are using the wrong Enum for comparison with the RowType property. It is one of the DataControlRowType values which indicate if the Row is a Header, Data, Footer etc.
Use the Row.RowState property to check for the Alternate Row.
Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='ghostwhite'")
If (e.Row.RowState And DataControlRowState.Alternate) = DataControlRowState.Alternate Then
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='WhiteSmoke'")
Else
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White'")
End If
End If
End Sub
Re: [2005] Gridview row color change on mouseover
Thanks your help bruve.
I solved the problem by using your code.
vBulletin Message
You must spread some Reputation around before giving it to brucevde again.
How to spread the reputation ?
Re: [RESOLVED] [2005] Gridview row color change on mouseover
Give reputation to a few other people, then come back and give it to bruce.