【问题标题】:CSS for Checkboxlist grouped under a checkbox in asp.net复选框列表的 CSS 分组在 asp.net 中的复选框下
【发布时间】:2013-03-30 05:39:31
【问题描述】:

是否可以显示复选框列表分组,如下图所示? 我正在使用 asp.net 控件并绑定数据。但我需要制作相同的风格。我如何使用 CSS 来做到这一点?

  <asp:DataList ID="dl_Groups_1" RepeatColumns="1"  runat="server" OnItemDataBound="dl_Groups_1_ItemDataBound" RepeatDirection="vertical" ShowFooter="False" ShowHeader="False">
        <ItemTemplate>
            <asp:CheckBox Font-Bold="true" runat="server" ID="chk_Group_1" Text='<%# Eval("category_type") %>' Value='<%# Eval("service_type_category_id") %>' onclick="OnGroupClick" />
            <asp:CheckBoxList runat="server" ID="chkServiceType_1" Style="padding-left: 20px" DataValueField="ServiceTypeID" DataTextField="Name" EnableViewState="true">
            </asp:CheckBoxList>
            <br />
        </ItemTemplate>
    </asp:DataList>

在浏览器中呈现的 HTML:

<table cellspacing="0" border="0" style="border-collapse:collapse;" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1">
    <tbody>

    <tr>
        <td>
            <span style="font-weight:bold;"><input type="checkbox" onclick="selectGroupAll(ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chk_Group_1);" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl00$chk_Group_1" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chk_Group_1"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chk_Group_1">Stay-In Facilities</label></span>
            <table border="0" style="padding-left: 20px" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1">
            <tbody>
            <tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl00$chkServiceType_1$0" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_0"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_0">DEF</label></td>
            </tr><tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl00$chkServiceType_1$1" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_1"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_1">ABC </label></td>
            </tr><tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl00$chkServiceType_1$2" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_2"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl00_chkServiceType_1_2">XYZ</label></td>
            </tr>
            </tbody>
            </table>
            <br>
        </td>
    </tr>

    <tr>
        <td>
            <span style="font-weight:bold;"><input type="checkbox" onclick="selectGroupAll(ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chk_Group_1);" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl01$chk_Group_1" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chk_Group_1"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chk_Group_1">Other Services</label></span>
            <table border="0" style="padding-left: 20px" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1">
            <tbody>
            <tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl01$chkServiceType_1$0" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_0"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_0">GHJ</label></td>
            </tr><tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl01$chkServiceType_1$1" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_1"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_1">IJK</label></td>
            </tr><tr>
                <td><input type="checkbox" name="ctl00$cphMain$ctlEsnSearchByServices$dl_Groups_1$ctl01$chkServiceType_1$2" id="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_2"><label for="ctl00_cphMain_ctlEsnSearchByServices_dl_Groups_1_ctl01_chkServiceType_1_2">MNO</label></td>
            </tr>
            </tbody>
            </table>
            <br>
        </td>
    </tr>

</tbody>
</table>

【问题讨论】:

  • 这是您希望新用户提出的问题,您已经成为会员 3 年了。你试过什么?你能告诉我们你的代码吗?您希望实现哪些特定的样式属性?
  • @JackPettinger 是的,我已经成为会员 3 年了。但这并不意味着我什么都知道。我没有添加有问题的代码,我只需要为这个场景实现 CSS 的想法。现在我添加了我用过的aspx。谢谢。

标签: asp.net css stylesheet checkboxlist


【解决方案1】:

好的,所以我设法做点什么。它看起来像这样:

DEMO

<section>
    <input type="checkbox" id="one" />
    <label for="one">Check One</label>
    <ul class="subCheck">
        <li>
            <input type="checkbox" id="subOne" />
            <lable for="subOne">subTwo</lable>
        </li>
        <li>
            <input type="checkbox" id="subTwo" />
            <lable for="subTwo">subTwo</lable>
        </li>
        <li>
            <input type="checkbox" id="subThree" />
            <lable for="subThree">subTwo</lable>
        </li>

    </ul>
</section>

还有 CSS:

section{
    float: left;
    position: relative;
    width: 100%; }

section:before{
    background: #000;
    content: "";
    height: 81px;
    left: 8px;
    position: absolute;
    top: 3px;
    width: 1px;
    z-index: 1; }

input[type="checkbox"]{
    float: left;
    margin: 2px;
    width: auto; }

label{
    float; left;
    margin: 0 0 0 5px;
    width: auto; }

ul{
    clear: both;
    float: left;
    list-style: none;
    margin: 5px 0 0;
    padding: 0 0 0 20px;
    width: 100%; }

ul li{
    float: left;
    margin: 0 0 5px;
    position: relative;
    width: 100%; }

li:before{
    background: #000;
    content: "";
    height: 1px;
    left: -11px;
    position: absolute;
    top: 8px;
    width: 14px; }

input, label, ul{
    position: relative;
    z-index: 2; }

HTML 仅供参考,我认为 CSS 正是您所寻找的。玩得开心。

【讨论】:

  • 您在示例中使用的
    是什么?我使用的控件将 HTML 呈现为表格和复选框。
  • @Anuya
    标签定义文档中的部分。例如章节、页眉、页脚或文档的任何其他部分。它带有 HTML5,但您可以使用
    或其他任何东西:P.
  • 请查看在浏览器中呈现的 HTML,并帮助我提出所需的样式。我不能使用 div,因为控件呈现的 HTML 没有 div。它是跨度和表格的。请看一下
猜你喜欢
相关资源
最近更新 更多
热门标签