2009-11-23 127 views
0

我有一個multiselectlist的問題,如果我將dropObjectcategories懸停在調試模式下,它包含4個應該選擇的項目。MultiSelectList does not make selected 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); 

它仍然獲取呈現不選擇任何像這樣的項目:

<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> 

什麼可能是錯在這裏?

/M

+0

我已經努力使它列表而不是相同的結果 – 2009-11-23 09:05:53

+0

_bs.GetObjectcategories()的類型是什麼?確保「ObjectcategoryID」與選定列表中的項目類型相同。 – LukLed 2009-11-23 12:18:51

+0

_bs.GetObjectcategories()是:IQueryable 和ObjectcategoryID是一個i​​nt – 2009-11-23 12:49:34

回答

1

試着這麼做:

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

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

是否行得通?

+0

nopes :(現在我甚至沒有在調試模式下count count> 0選項 – 2009-11-23 13:33:25

+0

bo.Objectcategories是否包含任何元素?如果沒有,你想被選中嗎? – LukLed 2009-11-23 13:36:50