I'm sure you know you can alternate background row color of your gridview just by throwing a 

<AlternatingRowStyle BackColor="#FFFFF0" /> 

 in there.    Perhaps you also know how to set a mouseover row highlight:

 

Protected Sub hotelsgridview_rowdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffffc0'")

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")

end if

end sub

 

but if you try doing both, when your onmouseout runs after moving over the menu, all your row background colors will be reset to white.  So how do you keep your alternating row color for the onmouseout?  I'm glad you asked.  This was a really popular method back in the day, and I'm sure this is what AlternatingRowStyle is doing behind the scenes:  Enter Stage Right:  MOD. 

MOD is a function that basically divides two numbers and gives you the remainder.  If the remainder is 0 then the first number is divisible cleanly by the second number.  In terms of our alternating row style, if the index of the row being databound is divisible by 2, then that's one color.  If it's not, than that's the other color.  The code looks like this:

 

Protected Sub hotelsgridview_rowdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffffc0'")
 If e.Row.RowIndex Mod 2 = 0 Then
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
            Else
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fffff0'")
            End If

        
end if

end sub