目前,我有这个:

<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/

10-09 03:26