0

我有这个代码。它总是falesitem.Selected

<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 + ", ";
        }
    }
}

知道有什么问题吗?谢谢。。

4

1 回答 1

2

尝试这个...

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

values = values.TrimEnd(',');
于 2013-04-05T06:29:29.530 回答