【问题标题】:How to Place a button next to ListItem如何在 ListItem 旁边放置一个按钮
【发布时间】:2012-11-16 12:46:38
【问题描述】:

如何在每个列表项旁边放置一个按钮?

<asp:CheckBoxList ID="lstBrembo" runat="server">
    <asp:ListItem Text="Popular" Value="9"></asp:ListItem> // <--- button here
    <asp:ListItem Text="Pads" Value="70"></asp:ListItem>
    <asp:ListItem Text="Discs" Value="72"></asp:ListItem>
    <asp:ListItem Text="Drums" Value="73"></asp:ListItem>
    <asp:ListItem Text="Handed Discs" Value="109"></asp:ListItem>
    <asp:ListItem Text="Brembo Max" Value="108"></asp:ListItem>
</asp:CheckBoxList>

每次我尝试在列表项之后或在其中插入 a 时,都会出现解析错误。我需要一个按钮。

有什么想法吗?

HTML:

<div id="MainContentPlaceHolder_pnlBrembo" class="groupbox">
    <fieldset>
        <legend>
            BREMBO
        </legend>
    <input type="submit" name="ctl00$MainContentPlaceHolder$ctl02" value="select all" class="selectAllButton" />
    <table id="MainContentPlaceHolder_lstBrembo">
            <tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_0" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$0" value="9" /><label for="MainContentPlaceHolder_lstBrembo_0">Popular</label></td>
            </tr><tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_1" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$1" value="70" /><label for="MainContentPlaceHolder_lstBrembo_1">Pads</label></td>
            </tr><tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_2" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$2" value="72" /><label for="MainContentPlaceHolder_lstBrembo_2">Discs</label></td>
            </tr><tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_3" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$3" value="73" /><label for="MainContentPlaceHolder_lstBrembo_3">Drums</label></td>
            </tr><tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_4" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$4" value="109" /><label for="MainContentPlaceHolder_lstBrembo_4">Handed Discs</label></td>
            </tr><tr>
                <td><input id="MainContentPlaceHolder_lstBrembo_5" type="checkbox" name="ctl00$MainContentPlaceHolder$lstBrembo$5" value="108" /><label for="MainContentPlaceHolder_lstBrembo_5">Brembo Max</label></td>
            </tr>
        </table>

    </fieldset>
</div>

【问题讨论】:

  • 你能粘贴渲染输出 (HTML) 吗?
  • @Muhammad 我认为这是不可能的。
  • @SowmyaShivaram 为您粘贴了 HTML。
  • 使用中继器并在中继器内部放置复选框列表
  • @LittleSweetSeas 添加的功能所有额外的复杂性......不值得付出努力,特别是因为我想从代码中填写列表。

标签: asp.net html css button webforms


【解决方案1】:

为此请使用其他控件,例如 ListView 或 Repeater。默认的 checkBoxList 不会轻易地为您提供这种能力。使用数据绑定控件,您可以根据需要对其进行格式化。

【讨论】:

  • 最后我使用了DataRepeater,它更简单,正是我所需要的。谢谢。
【解决方案2】:

正如 Brian Mains 所说,使用中继器或 listview insted

这是 ListView 的简单示例:

<asp:ListView ID="lvBrembo" runat="server">
        <LayoutTemplate>
            <table id="lstBrembo" border="0">
                <tbody runat="server" id="itemPlaceholder">
                </tbody>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:CheckBox ID="chbSelection" Text='<%# Eval("name") %>' Checked='<%# Eval("selected") %>' runat="server" />
                </td>
                <td>
                    <asp:Button ID="btnDetails" Text='<%# Eval("link") %>' runat="server" />
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>

示例中使用的类:

class Brembo
    {
        public string name {get;set;}
        public string link {get;set;}
        public bool selected {get;set;}
        public int value {get;set;}
    }

【讨论】:

    猜你喜欢
    • 2021-11-24
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    相关资源
    最近更新 更多