Change row color in Gridview on mouse over

If you have the need to change the row color of a row in a gridview when you mouse over (and mouse out) you can add some code to the RowDataBound event.

Here is a sample:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{
//Only apply to data rows
if (e.Row.RowType == DataControlRowType.DataRow)
{

//Add mouse over event to change row background color
e.Row.Attributes.Add(“onmouseover”, “this.style.backgroundColor=’Yellow'”);

//Add mouse out event to change row background color back to white
e.Row.Attributes.Add(“onmouseout”, “this.style.backgroundColor=White”);

}

}

Here is the blog site where I found this sample.

Advertisements

2 thoughts on “Change row color in Gridview on mouse over

Got something to add?

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