62,073
社区成员
发帖
与我相关
我的任务
分享
前台代码: <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
</asp:CheckBoxList >
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
后台代码:
protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
foreach (ListItem li in this.CheckBoxList1.Items)
{
if (li.Selected == true)
{
str += li.Value;
}
}
Response.Write(str);
}
if (this.CheckBox1.Checked = true)
{
string str = this.CheckBox1.Text;
}