CheckBoxList不输出标签

发布于 2024-12-19 00:07:09 字数 1656 浏览 5 评论 0 原文

在我的基于 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 的项目中复制此代码,则效果很好。有人遇到过这个问题吗?有什么建议吗?

谢谢纳斯

In one of my ASP.Net and Sitecore CMS based page I am using CheckBoxList control but somehow it's not outputting the label in the HTML.

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

In Code behind file I am loading the list:

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

When I view the code in the browser it appears as

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

It works fine if I copy this code in a non Sitecore based project. Is there anyone come across this problem? any suggestion?

Thanks

Nas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱&纷飞 2024-12-26 00:07:09

就其价值而言,CheckBoxList 在我的 Sitecore 6.5 机器上渲染得很好。

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

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

For what it's worth, a CheckBoxList renders just fine on my Sitecore 6.5 box.

The output of your CheckBoxList is not standard. The default asp:CheckBoxList control renders the checkboxes in a table not a div. Even if you change RepeatLayout="Flow" on your <ASP:CheckBoxList tag you would still not get a div; on my testing I got a span.

I would image you have a control adapter, or something, modifying the output.

夜雨飘雪 2024-12-26 00:07:09

System.Web.UI.WebControls 中有一个 ListItem 控件,但 Sitecore.Web 中也有一个名为 ListItem 的 Sitecore 控件.UI.HtmlControls。您的代码中是否存在一些关于您所指的代码的混乱?

There is a ListItem control in System.Web.UI.WebControls but also there is a Sitecore control called ListItem in Sitecore.Web.UI.HtmlControls. Could there be some confusion in your code as to which one you are referring to ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文