for (int counter = 0; counter < countSelected; counter++)
{
string groupName = txt_GroupName.Text;
//Get GroupID from the created group
string GroupIDQueryText = "SELECT GroupID FROM tbl_group WHERE GroupName ";
int groupID = Convert.ToInt32(server.performQuery(GroupIDQueryText, groupName, MySqlDbType.VarChar));
//To get User ID
string firstName = ListBoxMembers.SelectedItems[counter].Value;
}
This isn’t returning the selected value, but instead returns the 1st person in the list even if I haven’t selected it. Where am I going wrong?
System.Web.UI.WebControls does not contain defenition for listboxmembers.selectedItems error
You are using
.Itemswhich is the collection of all items in theListBox. I think you intend to use.SelectedItems(documentation on MSDN).EDIT Web ListBox controls are different than WinForms ListBox controls, so knowing that context is very valuable. Here’s an article from MSDN on how to determine the selected items in a multi-selection list control (scroll down to the multi-selection section). The idea is to loop through all
.Itemsand check the.Selectedproperty on each.