2011-12-02 47 views
3

在我的一個基於ASP.Net和Sitecore CMS的頁面中,我使用CheckBoxList控件,但不知何故它不會在HTML中輸出標籤。CheckBoxList不輸出標籤

<asp:CheckBoxList runat="server" ID="chkListBrochure" CssClass="checkbox_single" /> 

在代碼隱藏文件我加載列表:

foreach (var item in itemList) 
     { 
      var newListItem = new ListItem(item.Title, item.Code); 
      newListItem.Selected = item.Selected; 
      chkListBrochure.Items.Add(newListItem); 
     } 

當我查看它顯示爲

<div id="body_0_content_0_content_1_chkListBrochure" class="checkbox_single"> 
    <input id="body_0_content_0_content_1_chkListBrochure_0" class="" type="checkbox"  
     name="body_0$content_0$content_1$chkListBrochure$0"> 
    <input id="body_0_content_0_content_1_chkListBrochure_1" class="" type="checkbox" 
    checked="checked" name="body_0$content_0$content_1$chkListBrochure$1"> 
    <input id="body_0_content_0_content_1_chkListBrochure_2" class="" type="checkbox" 
    name="body_0$content_0$content_1$chkListBrochure$2"> 
    <input id="body_0_content_0_content_1_chkListBrochure_3" class="" type="checkbox" 
    checked="checked" name="body_0$content_0$content_1$chkListBrochure$3"> 
    <input id="body_0_content_0_content_1_chkListBrochure_4" class="" type="checkbox" 
    name="body_0$content_0$content_1$chkListBrochure$4"> 
    <input id="body_0_content_0_content_1_chkListBrochure_5" class="" type="checkbox" 
    checked="checked" name="body_0$content_0$content_1$chkListBrochure$5"> 
</div> 

,如果我複製此代碼工作正常,在瀏覽器的代碼在基於非Sitecore的項目中。有沒有人遇到過這個問題?任何建議?

感謝

納斯

+0

我認爲我們需要更多信息。 Var數據類型是itemList,什麼是item.Selected和item.Code?他們是爲了獲取字段值而做出的擴展方法嗎? Item.Id是否工作 – Holger

回答

0

有在System.Web.UI.WebControls一個ListItem控制,但也有一個Sitecore的控制Sitecore.Web.UI.HtmlControls稱爲ListItem。你的代碼中可能會出現一些混淆,指出你指的是哪一個?

+1

使用Sitecore ListItem會提供編譯錯誤,因爲沒有構造函數,至少在Sitecore 6.5中有兩個參數。此外,您不能將Sitecore ListItem添加到ASP:CheckBoxList項目。 –

1

對於它的價值,CheckBoxList在我的Sitecore 6.5框中呈現得很好。

CheckBoxList的輸出不是標準的。默認asp:CheckBoxList控件呈現table而不是div中的複選框。即使您在<ASP:CheckBoxList標籤上更改RepeatLayout="Flow",您仍然不會收到div;在我的測試中,我得到了一個span

我想你有一個控制適配器,或者其他東西,修改輸出。