CheckBoxList不能正常工作

本文关键字:工作 常工作 不能 CheckBoxList | 更新日期: 2023-09-27 18:07:48

我有这个代码。它总是给出item.Selected

fales
<asp:Literal ID="LiteralEmployeeList" runat="server" />
<asp:LinkButton ID="LinkButtonRecipients" runat="server">Add/Remove Recipients</asp:LinkButton>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderTo" runat="server" TargetControlID="LinkButtonRecipients"
                    DropShadow="true" PopupControlID="PanelEmployeeList" OkControlID="ButtonOk" EnableViewState="true">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelEmployeeList" runat="server" Width="200" Height="100" ScrollBars="Vertical">
    <div id="DivPanelBody">
        <div id="DivList">
            <asp:CheckBoxList ID="CheckBoxListEmployee" runat="server" EnableViewState="true"
                onselectedindexchanged="CheckBoxListEmployee_SelectedIndexChanged">
            </asp:CheckBoxList>                
        </div>
        <div id="DivControls">
            <asp:Button ID="ButtonOk" runat="server" Text="Ok" />
        </div>
    </div>
</asp:Panel>

CheckBoxList绑定到一个数据源及其工作。

protected void CheckBoxListEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
    LiteralEmployeeList.Text = string.Empty;
    foreach (ListItem item in CheckBoxListEmployee.Items)
    {
        if (item.Selected)
        {
            LiteralEmployeeList.Text += item.Text + ", ";
        }
    }
}

你知道怎么回事吗?谢谢. .

CheckBoxList不能正常工作

try this…

for (int i = 0; i < interestedIN.Items.Count; i++)
{
   if (interestedIN.Items[i].Selected)
   {
       values += interestedIN.Items[i].Value + ",";
   }
}
values = values.TrimEnd(',');