How To Change Row Color of Gridview on Mouse Over Event


For my example, I’m using alternating background colors on rows (which you should do too, it makes things so much more readable). This causes me to add a couple extra lines so that I make sure I’m setting my rows back to the correct color on MouseOut.

Here is the code for that :

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add(“onmouseover”, “this.style.backgroundColor=’#FFFFE1′;”);
e.Row.Attributes.Add(“onmouseout”, “this.style.backgroundColor=’#f7fff8′;”);
}
else
{
e.Row.Attributes.Add(“onmouseover”, “this.style.backgroundColor=’#FFFFE1′;”);
e.Row.Attributes.Add(“onmouseout”, “this.style.backgroundColor=’#eefef0′;”);
}
}

}

Advertisements

One thought on “How To Change Row Color of Gridview on Mouse Over Event

  1. Pingback: asp.net, c#,javascript

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