I have a ListBox that has values. Once a user clicks on a button I need to know what values in the list box is selected. I know this is easy and I am missing something simple. The Listbox is setup to allow the user to select multiple items.
this.lstInstructorID.Items.Clear();
var list = new List<System.Collections.DictionaryEntry>();
while (reader2.Read())
{
strValue = reader2["InstructorName"].ToString();
strID = reader2["InstructorID"].ToString();
list.Add(new System.Collections.DictionaryEntry(reader2["InstructorName"], reader2["InstructorID"]));
}
To loop selected items in a listbox (try not to use object class)
Code:
List<object> selectedList = new List<object>();
for (int i = 0; i < LstMyListBox.SelectedItems.Count; i++)
{
selectedList.Add((object)LstMyListBox.SelectedItems[i]);
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.