这是动态添加复选框的 HTML 代码
<asp:Panel ID="Panel1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Text Catogaries"></asp:Label>
<br />
<br />
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate >
<table>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("CategoryName") %>'/>
</td>
</table>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<br />
</asp:Panel>
这是我在按钮后面用来检索复选框值的代码
foreach (Control cr in Repeater1.Controls)
{
// controls within repeater item
foreach (Control c in cr.Controls)
{
CheckBox chk = c as CheckBox;
if (chk != null)
{
list.Add(chk.text)
}
}
问题是如果我在列表中添加值的情况下,控制不会进入。如何在列表中添加价值。