GridView Mouse Over Row Highlighting

Posted: September 27, 2010 in ASP.Net

If you are looking at creating mouse over row highlighting on a GridView control, you can try the following:
ASP.Net (Code Behind)
Add the following attributes for each row in the GridView control:

 ' Routine for when each row is created for the gridview
 Protected Sub p_grd_site_details_RowCreated(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.className='grd_mouse_over';this.style.cursor='pointer';")
         e.Row.Attributes.Add("onmouseout", "this.className='grd_mouse_out';")
     End If
 End Sub

CSS
Add the following styles:

.grd_mouse_over{background-color:#FAE6CB;}
.grd_mouse_out{background-color: #FFFFFF;}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s