checkboxlist给label赋值

来源:百度知道 编辑:UC知道 时间:2024/06/03 20:29:23
checkboxlist1有多项,勾选checkboxlist的每一项的值都会在label1上显示出来,当然已勾选的项在点击一次,label上所对应项也会消失,大家帮个忙

aspx
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="1">aaaaa</asp:ListItem>
<asp:ListItem Value="2">bbbb</asp:ListItem>
<asp:ListItem Value="3">ccccc</asp:ListItem>
</asp:CheckBoxList>
<asp:Label ID="Label1" runat="server"></asp:Label>

.cs

protected void CheckBoxList1_SelectedIndexChanged ( object sender, EventArgs e )
{
CheckBoxList checkBoxList = sender as CheckBoxList;

string strSelectedTexts = String.Empty;
string strSelectedValues = String.Empty;

foreach ( ListItem item in checkBoxList.Items )
{
if (