我试图从一个淹没列表中选择多个项目,我正在使用引导,但我的问题是:我只能获得第一个选定的项目,不能得到其他选定的项目。
我的代码(样式和脚本):
<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 -->
<script type="text/javascript">
$('select').selectpicker();
</script>我的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);
}正如我说的..。我只能拿到第一件东西,任何人都能帮我吗?谢谢
诚挚的问候
发布于 2020-01-30 00:57:11
The DropDownList
允许用户从下拉列表中选择单个项。
ListBox允许您选择多个项:
<asp:ListBox CssClass="selectpicker"
ID="DropDownList1"
runat="server"
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:ListBox>您的其余代码应该按原样工作,可能会更新ID。杨木片有一个使用引导程序的示例。
https://stackoverflow.com/questions/59976316
复制相似问题