user2653652 user2653652 - 6 months ago 39
CSS Question

ASP.NET - JavaScript onmouseout get original background

I added this code into my gridview rowdataBound:

e.Row.Attributes.Add("onmouseover", "'#E2DED6';'pointer'")

Now onmouseout I want the original background from the the CSS, I don't know much from JavaScript and jQuery so I would like to keep it to inline JavaScript if possible.

I'm looking for something like this:

e.Row.Attributes.Add("onmouseout", "'default'")


Since you want to keep it inline:

e.Row.Attributes.Add("onmouseout", "''")

That should remove the inline style, and default to the normal stylesheet.

You can also be more "sledge hammer", and remove the whole style attribute (this will remove all set inline styles though):

e.Row.Attributes.Add("onmouseout", "this.removeAttribute('style')")

This assumes that you have a css/class set on the element to default to.

An easier way to maintain this would be to use css classes instead:

e.Row.Attributes.Add("onmouseover", "this.className='myHoverClass'")
e.Row.Attributes.Add("onmouseout", "this.className=''")

Define your class in a stylesheet (or in the page):

.myHoverClass {
    background-color: #E2DED6;
    cursor: pointer;