tags:

views:

72

answers:

1

Hello

I have a problem with a multiselectlist, if I hover dropObjectcategories in debug-mode it contains 4 items that should be selected.

List<int> selectedObjectcategoryIDs = new List<int>();

foreach (Objectcategory item in bo.Objectcategories)
{
    selectedObjectcategoryIDs.Add(item.ObjectcategoryID);
}

MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);

still it gets rendered without any items selected like this:

<select id="dropObjectcategories" multiple="multiple" name="dropObjectcategories"><option value="3">Airplanes</option><option value="10">Cars</option><option value="8">Computers</option><option value="9">Thingies</option></select>

what might be wrong here?

/M

+1  A: 

Try something like:

var selectedObjectcategoryIDs =
  from oc in bo.Objectcategories
  select oc.ObjectcategoryID;

MultiSelectList dropObjectcategories = new MultiSelectList(_bs.GetObjectcategories(), "ObjectcategoryID", "ObjectcategoryName", selectedObjectcategoryIDs);

Does it work?

LukLed
nopes :( now I didnt even get count >0 selected items in debug mode
molgan
Do bo.Objectcategories containt any elements? If it doesn't, what do you want to be selected?
LukLed