How to add style from code behind?

asp.net, c#, css, hyperlink

Solution

`:hover` is a selector, and not a style. What you're doing in your example is adding inline styles to an element, and a selector equivalent for that obviously doesn't make much sense.

You can add a class to your link: `hlRow.CssClass = 'abc';` And define your class as such:

a.abc:hover {
    ...
}

Problem

I want to add a style `A:Hover` to a HyperLink control from code behind. I can do like this : ``` HyperLink hlRow = new HyperLink(); hlRow.Style.Add("color", "#000000"); hlRow.Style.Add("text-decoration", "none"); ``` But how can I add styles for `A:Hover` for the hyperlink control? Do I need to define a class and associate that class with this control, if yes how?

Original source