【发布时间】:2019-01-30 17:42:55
【问题描述】:
我正在尝试将下拉列表(从 sql server 填充的列表)中的项目添加到 asp.net 中的列表框(网络表单)。第一项添加没有问题,但就是这样。从下拉列表中选择第二项时,没有任何反应。这是下拉菜单的 SelectedIndexChanged 事件中使用的代码:
下拉列表和列表框都将 AutoPostBack 设置为 true。还需要做什么?不应该这么简单吗:
protected void DropDownList_SelectedIndexChanged(object sender,
EventArgs e)
{
listBox.Items.Add(DropDownList.SelectedItem);
}
<asp:DropDownList ID="DropDownList" runat="server"
EnableViewState="true" AutoPostBack="true"
OnSelectedIndexChanged="DropDownList_SelectedIndexChanged"
Visible="true"></asp:DropDownList>
<asp:ListBox runat="server" ID="listBox" CssClass="form-control"
AutoPostBack="true" EnableViewState="true"></asp:ListBox>
我需要将每个被选中的项目都添加到列表框中——而不仅仅是第一个项目。
【问题讨论】:
标签: c# asp.net .net webforms listbox