【问题标题】:CheckBoxList not outputing the labelCheckBoxList 不输出标签
【发布时间】:2011-12-02 14:27:54
【问题描述】:

在我的一个基于 ASP.Net 和 Sitecore CMS 的页面中,我正在使用 CheckBoxList 控件,但不知何故它没有在 HTML 中输出标签。

<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 的项目中,它可以正常工作。有没有人遇到过这个问题?有什么建议吗?

谢谢

纳斯

【问题讨论】:

  • 我认为我们需要更多信息。 Var 数据类型是 itemList,item.Selected 和 item.Code 是什么?它们是您为获取字段值而制作的扩展方法吗? item.Id 工作吗

标签: asp.net sitecore checkboxlist


【解决方案1】:

不管怎样,CheckBoxList 在我的 Sitecore 6.5 盒子上渲染得很好。

CheckBoxList 的输出不是标准的。默认的asp:CheckBoxList 控件将复选框呈现在table 而不是div 中。即使您更改了&lt;ASP:CheckBoxList 标签上的RepeatLayout="Flow",您仍然不会得到div;在我的测试中,我得到了span

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

【讨论】:

    【解决方案2】:

    System.Web.UI.WebControls 中有一个ListItem 控件,在Sitecore.Web.UI.HtmlControls 中还有一个名为ListItem 的Sitecore 控件。您的代码中是否存在一些混淆,您指的是哪一个?

    【讨论】:

    • 使用 Sitecore ListItem 会产生编译错误,因为没有构造函数,至少在 Sitecore 6.5 中没有接受两个参数。此外,您不能将 Sitecore ListItem 添加到 ASP:CheckBoxList 项目中。
    猜你喜欢
    • 1970-01-01
    • 2013-07-17
    • 2011-01-17
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多