c# - CheckBoxList 子级 CSS

标签 c# asp.net css

目前,我有这个:

<asp:CheckBoxList ID="chkSections" runat="server" onselectedindexchanged="chkSections_SelectedIndexChanged"></asp:CheckBoxList>

...生成这个:

<table border="0" id="ctl00_cpBody_chkSections">
    <tbody><tr>
        <td><input type="checkbox" name="ctl00$cpBody$chkSections$0" id="ctl00_cpBody_chkSections_0"><label for="ctl00_cpBody_chkSections_0">All Sections</label></td>
    </tr><tr>
        <td><input type="checkbox" name="ctl00$cpBody$chkSections$1" id="ctl00_cpBody_chkSections_1"><label for="ctl00_cpBody_chkSections_1">Personal Health Status and Health History</label></td>
    </tr><tr>
        <td><input type="checkbox" name="ctl00$cpBody$chkSections$2" id="ctl00_cpBody_chkSections_2"><label for="ctl00_cpBody_chkSections_2">Physical Activity and Fitness</label></td>
    </tr>
</tbody></table>

问题:我希望生成的所有input 字段都具有一个特定的类。不想使用 jQuery。

最佳答案

您还可以使用 ListItem 的属性在服务器端设置类名:

protected void Page_Load(object sender, EventArgs e)
{
    foreach (ListItem item in chkSections.Items)
        item.Attributes["class"] = "class_item";
}

关于c# - CheckBoxList 子级 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12962061/

相关文章:

javascript - 在 Jquery 中为 mouseenter 上的阴影设置动画

CSS first-child 被 LESS 覆盖

c# - 如何在 stacklayout xamarin forms pcl 上填充图像

c# - 使用 'fixed' 作为指针语句

C# + Entity Framework : Convert multiple group by query to nested JSON

javascript - 在 jquery javascript 中选择第 n 个子级

c# - 如何以编程方式将按钮上的可见性绑定(bind)到 C# 中的 INotifyPropertyChanged bool 属性?

C# XNA 4.0 异常 : "Cannot Open File"

c# - 如何以编程方式向现有 GridView 添加附加列?

html - 将专门放置的图像放在 div -HTML/CSS 中