Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Gridview row color change on mouseover

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [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.

    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:
    1. Protected Sub grdStatusMaster_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdStatusMaster.RowDataBound
    2.         If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Then
    3.  
    4.             e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='ghostwhite'")
    5.             If e.Row.RowType = ListItemType.Item Then
    6.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='WhiteSmoke'")
    7.             Else
    8.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White'")
    9.             End If
    10.  
    11.         End If
    12.        
    13.  
    14.     End Sub
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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 ?
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2005] Gridview row color change on mouseover

    Give reputation to a few other people, then come back and give it to bruce.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width