2011-12-02 45 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

我想你有一个控制适配器,或者其他东西,修改输出。