gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:05 25 4
gpt4 key购买 nike

我正在创建一个带有这样标记的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com