How to set a CSSClass for a dynamically generated开发者_开发问答 label in asp.net with C#
Label lbl = new Label();
lbl.Text = "Hello World!";
lbl.CssClass = "red_and_bold";
When You create Label then set its CssClass property:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx
If you mean setting it server-side you can use WebControl.CssClass property:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx
Label lblPrivacyGender = new Label(); lblPrivacyGender.Attributes.Add("class", "spanHeaderStyle"); lblPrivacyGender.Text = "Gender: ";
Above spanHeaderStyle is a CssClass which is previously defined
精彩评论