How to get the select value in a multiple dropdownlist
-
hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:
List dep = new List();
foreach (ListItem item in sltnamedep.Items)
{if (item.Selected) { dep.Add(item.Text); } } for (int i = 0; i < dep.Count; i++) Response.Write(dep\[i\]);
-
hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:
List dep = new List();
foreach (ListItem item in sltnamedep.Items)
{if (item.Selected) { dep.Add(item.Text); } } for (int i = 0; i < dep.Count; i++) Response.Write(dep\[i\]);
-
hi, I'm trying to get multiple values that was selected in a dropdown list, the problem is that it's only returning one value, if I select two or more values only give me one, here's the code:
List dep = new List();
foreach (ListItem item in sltnamedep.Items)
{if (item.Selected) { dep.Add(item.Text); } } for (int i = 0; i < dep.Count; i++) Response.Write(dep\[i\]);
Make sure you have focus on the control. MSDN says:
Quote:
Items appear selected only when the ListView control has focus. To select items in response to a user action such as a button click, be sure to call the Focus method in addition to setting this property.