c# - 将项目添加到 Sitecore 组合框

标签 c# sitecore sitecore6

我正在创建一个带有这样标记的 Sitecore Sheer UI 向导

<WizardFormIndent>
   <GridPanel ID="FieldsAction" Columns="2" Width="100%" CellPadding="2">
      <Literal Text="Brand:" GridPanel.NoWrap="true" Width="100%" />
      <Combobox ID="Brand" GridPanel.Width="100%" Width="100%">
         <!-- Leave empty as I want to populate available options in code -->
      </Combobox>
   <!-- Etc. -->
</WizardFormIndent>

但我似乎无法在旁边的代码中找到向组合框“品牌”添加选项的方法。有谁知道如何完成下面的代码?

[Serializable]
public class MySitecorePage : WizardForm
{
    // Filled in by the sheer UI framework
    protected ComboBox Brands;

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!Context.ClientPage.IsEvent)
        {
             IEnumerable<Brand> brandsInSqlDb = GetBrands();

             // this.Brands doesn't seem to have any methods
             // to add options
        }
    }

}

最佳答案

首先,我假设您使用的是 Sitecore.Web.UI.HtmlControls 中的 Sitecore Combobox(而不是 Telerik 控件,例如)?

在 Reflector 中查看,它最终会做这样的事情:

foreach (Control control in this.Controls)
{
    if (control is ListItem)
    {
        list.Add(control);
    }
}

所以我希望您需要通过您的 brandsInSqlDb 构建一个循环,实例化一个 ListItem 并将其添加到您的 Brands Combobox。类似的东西

foreach (var brand in brandsInSqlDb)
{
    var item = new ListItem();
    item.Header = brand.Name; // Set the text
    item.Value = brand.Value; // Set the value

    Brands.Controls.Add(item);
}

关于c# - 将项目添加到 Sitecore 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15270898/

相关文章:

c# 遍历 ListView 项并通过单击按钮一次在文本框中显示一行

workflow - Sitecore 安全和工作流程

c# - 正则表达式匹配但忽略输出中的特定字符

c# - 将事务范围添加到 Parallel.Foreach

sitecore - 如何将 droplink 链接到 Sitecore 中的树列表

Sitecore 站点/项目发布在初始化时挂起

image - Sitecore:带有预览图像的子布局

sitecore - 如何以编程方式将项目发送到工作流程?

telerik - 自定义 Sitecore 富文本编辑器的默认配置

c# - 我怎样才能将一些按键转换为其他按键?