Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a SelectList with multiple selected values?

Tags:

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?

like image 485
Mariah Avatar asked Oct 20 '11 17:10

Mariah


People also ask

How do I select multiple selections in dropdown?

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.

How show multiple selected values in dropdown in PHP?

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.


1 Answers

You want to use MultiSelectList instead which has a constructor to meet your needs:

public MultiSelectList(     IEnumerable items,     string dataValueField,     string dataTextField,     IEnumerable selectedValues ) 
like image 66
Robert Levy Avatar answered Sep 19 '22 06:09

Robert Levy