我正在尝试从drowpdownlist中选择多个项目,我正在使用引导程序,但是我的问题是:我只能得到第一个选定的项目,不能让其他选定的项目。
我的代码(样式和脚本):
<link rel="stylesheet" href="Content/bootstrap.min.css" /> <!-- Bootstrap v4.4.1 -->
<link rel="stylesheet" href="Content/bootstrap-select.css" /> <!-- Bootstrap-select v1.13.1 -->
<script src="js/jquery-1.9.1.js"></script>
<script src="Scripts/bootstrap.bundle.min.js"></script>
<script src="Scripts/bootstrap-select.min.js"></script> <!-- Bootstrap-select v1.13.1 -->
我的DDL:
<asp:DropDownList CssClass="selectpicker" ID="DropDownList1" runat="server" multiple data-live-search="true" SelectionMode="multiple">
<asp:ListItem>Brasil</asp:ListItem>
<asp:ListItem>Colombia</asp:ListItem>
<asp:ListItem>United States</asp:ListItem>
<asp:ListItem>Frannce</asp:ListItem>
<asp:ListItem>Italy</asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
</asp:DropDownList>
我使用按钮,这是OnClick命令:
protected void btnSend_Click(object sender, EventArgs e)
{
string selectedItems = "";
foreach (ListItem item in DropDownList1.Items)
{
if (item.Selected)
{
selectedItems += item.Text + "\\n";
}
}
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + selectedItems + "');", true);
}
正如我说的那样。我只能得到第一项,任何人都可以帮助我吗?谢谢
最诚挚的问候