I need to select multiple values from a ListBox. I enabled the SelectionMode
as multiple
. I am able to select multiple values, but only one value is going to the database. I used Listbox.SelectedValue.ToString()
.
Please help me out how to get that multiple values into the database?
ListBox.SelectedValue will return only one value. You need to use ListBox.SelectedItems property and then adjust your code accordingly to insert multiple values into the database.
Using foreach loop we can get multiple selected values in 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.