我如何在每个列表项旁边放置一个按钮?
<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>
每次我尝试在列表项之后插入或在其中插入时,我都会得到一个解析错误。不知怎的,我需要一个按钮。
有什么想法吗?
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>
答案 0 :(得分:1)
使用替代控件,如ListView或Repeater。默认的checkBoxList不会轻易地为您提供此功能。使用数据绑定控件,您可以根据需要对其进行格式化。
答案 1 :(得分:0)
正如Brian Mains所说,使用repeater或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;}
}