Home > ASP.Net > How To Change Row Color of Gridview on MouseOver Event

How To Change Row Color of Gridview on MouseOver Event


Hi

try this code :

protected void GridView1_RowDataBound(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′;”);
}
}

}

Good Luck

Advertisements
Categories: ASP.Net
  1. January 7, 2009 at 9:53 am

    this is not working man
    i want to assign a css class name to element by javascript on client side. do u have solution?

  2. yasserzaid
    January 7, 2009 at 11:47 am

    ok saneer i am sorry for this mistake you can try this code with Row DataBound of your Gridview not in Row Created

    Hope this helps

    Best Regards

  3. Shaun
    January 12, 2009 at 9:49 pm

    There’s a better way to do this (taking into account your GridView’s ItemStyle and AlternatingItemStyle properties) – http://www.aspdotnetfaq.com/Faq/How-to-correctly-highlight-GridView-rows-on-Mouse-Hover-in-ASP-NET.aspx

  4. yasserzaid
    January 13, 2009 at 9:30 am

    Thank you Shaun for your Link

    Good Example but as you know there are many ways to do it

    Best Regards

    YZ

  1. No trackbacks yet.

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

%d bloggers like this: