【问题标题】:Setting a css class to HtmlInputCheckBox in C#在 C# 中将 css 类设置为 HtmlInputCheckBox
【发布时间】:2010-10-25 07:20:43
【问题描述】:

我正在 C# 中创建一个 HtmlInputCheckBox,我正在尝试为它设置一个 css,但我不能。谁能给我一个示例代码?
例如,下面的那个不起作用。

HtmlInputCheckBox FieldCtrl = new HtmlInputCheckBox();
FieldCtrl.ID = "CheckBox1";
FieldCtrl.Style = "CheckBox";

【问题讨论】:

  • 在您的示例中,您将字段定义为 Field,并且您正在引用它 FieldCtrl。这是示例中的错字还是您的代码中的问题?
  • 抱歉,打错了。错字已修复..

标签: c# asp.net .net css checkbox


【解决方案1】:

.Net 并没有直接暴露很多普通的 HTML 属性,但是你可以通过 Attributes 集合来访问它。

FieldCtrl.Attributes["class"] = "MyCssClass";

【讨论】:

  • 或者:HtmlInputCheckBox FieldCtrl = new HtmlInputCheckBox(); FieldCtrl.Attributes.Add("class", "className");
猜你喜欢
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 2018-12-11
  • 2014-04-24
相关资源
最近更新 更多