I'm trying to set multiple values in a select list:
SelectList List = new SelectList(MyListItems, "valField", "dataField", <selected values>);
What object/values do I use for to select multiple items?
To select multiple options in a drop-down list, use the multiple properties. It allows you to select more than one option while pressing CTRL key.
Get Multiple Selected Values of Select Dropdown in PHPAdd the multiple tag with select tag also define array with name property. Make sure the Fruits array is not empty, run a foreach loop to iterate over every value of the select dropdown. Display the selected values else show the error message to the user.
You want to use MultiSelectList instead which has a constructor to meet your needs:
public MultiSelectList( IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With