c# - 为动态生成的复选框设置 css 类

标签 c# asp.net .net

我有一系列要以编程方式添加到面板的复选框。我设置了 CssClass 属性,但没有设置控件的 CSS 类,它只是将它包装在具有该 CSS 类的范围内。有没有办法让它给复选框上课?我需要实际复选框上的类,因为在 javascript 中我是按类选择的。

这是我的代码:

        CheckBox checkbox = new CheckBox();
        checkbox.Text = checkboxText;
        checkbox.ID = checkboxID;
        checkbox.CssClass = "chkRoles";
        pnlMandatoryRoles.Controls.Add(checkbox);
        pnlMandatoryRoles.Controls.Add(new LiteralControl("<br>"));

最佳答案

替换:

checkbox.CssClass = "chkRoles" 

与:

checkbox.InputAttributes["class"] = "chkRoles"

关于c# - 为动态生成的复选框设置 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17054911/

相关文章:

javascript - 服务器端按钮单击事件未在 UpdatePanel 内触发

asp.net - 为什么此 View 模型值无法正确呈现?

.net - 如何在运行时转换类型?

c# - ASP.NET 3 层/3 层架构 - 如何分离 UI 和 BLL

c# - 如何在标签中显示指数?

asp.net - url 参数中使用的 TextBox 值

c# - 在 Windows 应用程序上验证代码签名证书

c# - 从列表框中清除选中的项目而不触发 itemcheck 事件

c# - SendAsync() 返回 422 无法处理的实体

c# - Visual Studio : How to properly build and specify the configurations and platforms for x64 and x86