简体   繁体   English

从列表框中选择多个项目

[英]Select multiple items from a listbox

I need to select multiple values from a ListBox. 我需要从列表框中选择多个值。 I enabled the SelectionMode as multiple . 我启用SelectionModemultiple I am able to select multiple values, but only one value is going to the database. 我可以选择多个值,但是只有一个值将进入数据库。 I used Listbox.SelectedValue.ToString() . 我使用了Listbox.SelectedValue.ToString()

Please help me out how to get that multiple values into the database? 请帮助我如何将多个值输入数据库?

ListBox.SelectedValue will return only one value. ListBox.SelectedValue将仅返回一个值。 You need to use ListBox.SelectedItems property and then adjust your code accordingly to insert multiple values into the database. 您需要使用ListBox.SelectedItems属性,然后相应地调整代码以将多个值插入数据库。

Using foreach loop we can get multiple selected values in ListBox 使用foreach循环,我们可以在ListBox中获得多个选定的值

    foreach (ListItem li in ListBox1.Items)
    {
        if (li.Selected)
        {
            lblValues.Text += li.Text+"<br/>";
        }
    }

Check this link for more in details: http://www.dotnetfox.com/articles/how-to-get-multiple-selected-value-in-listbox-control-Asp-Net-using-C-Sharp-1047.aspx 检查此链接以获取更多详细信息: http : //www.dotnetfox.com/articles/how-to-get-multiple-selected-value-in-listbox-control-Asp-Net-using-C-Sharp-1047。 aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM