tags:

views:

626

answers:

1

Hello

I have created a MultiSelectList like this:

MultiSelectList UsergroupID = new MultiSelectList(_ug.GetUsergroups(), "UsergroupID", "UsergroupName", u.Usergroups);

problem is the getting the list from u.Usergroups (that is EntitySet) to make the items selected.

Do I need to cast "u.Usergroups" to something in order for it to select those?

/M

+2  A: 

This can be solved by using LINQ and the "select new" keyword.

IEnumerable<SelectListItem> userGroups = 
from u in _ug.GetUsergroups()
select new SelectListItem {
   Text = u.UsergroupName,
   Value = u.UsergroupID,
   Selected = u.YourBoolean
};

Then you add the userGroups items to the MultiSelectList.

P.S. Not sure if it should be SelectListItem for the MultiSelectList type.

Mickel