我有这个代码。它始终为fales
item.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 + ", ";
}
}
}
任何想法都错了吗?感谢名单..
答案 0 :(得分:2)
试试这个......
for (int i = 0; i < interestedIN.Items.Count; i++)
{
if (interestedIN.Items[i].Selected)
{
values += interestedIN.Items[i].Value + ",";
}
}
values = values.TrimEnd(',');