开发者

MultiSelectList doesnt make items selected

开发者 https://www.devze.com 2022-12-12 10:18 出处:网络
I have a problem with a multiselectlist, if I hover dropObjectcategories in debug-mode it contains 4 items that should be selected.

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.Objectcategorie开发者_JS百科s)
{
    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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消