I am using VS2005 C#.
I am trying to convert my ListBox control to the use of DDL.
However in my function of adding a list of user to a specific role, it enables multiple selection in the ListBox.
I would like to change it to the use of DDL, which only allows single selection.
Below is the code:
string[] newusers = new string[UsersListBox.GetSelectedIndices().Length];
for (int i = 0; i < newusers.Length; i++)
{
newusers[i] = UsersListBox.Items[UsersListBox.GetSelectedIndices()[i]].Value;
}
The error pointed out that System.Web.UI.WebControls.DropDownList' does not contain a definition for 'GetSelectedIndices.
May I know what can I alter my code for the use of DDL instead of ListBox?
A
DropDownListcannot have multiple items selected, so there is not aGetSelectedIndices()method, as you have noticed. Instead there is aSelectedIndexproperty.