Sunday, June 19, 2011

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");
}
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More