How to add style from code behind? How to add style from code behind? asp.net asp.net

How to add style from code behind?


You can use the CssClass property of the hyperlink:

LiteralControl ltr = new LiteralControl();        ltr.Text = "<style type=\"text/css\" rel=\"stylesheet\">" +                    @".d                    {                        background-color:Red;                    }                    .d:hover                    {                        background-color:Yellow;                    }                    </style>                    ";        this.Page.Header.Controls.Add(ltr);        this.HyperLink1.CssClass = "d";


Use

HyperLink hlRow = new HyperLink();hlRow.Attributes.Add("Style", "color:#000000");


Try this:

Html Markup

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#">HyperLink</asp:HyperLink>

Code

using System.Drawing;using System.Web.UI;using System.Web.UI.WebControls;protected void Page_Load(object sender, EventArgs e){    Style style = new Style();    style.ForeColor = Color.Green;    this.Page.Header.StyleSheet.CreateStyleRule(style, this, "#" + HyperLink1.ClientID + ":hover");}