And*_*row 1 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>
Run Code Online (Sandbox Code Playgroud)
但我似乎找不到在旁边的代码中为组合框"Brand"添加选项的方法.有谁知道如何完成下面的代码?
[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
}
}
}
Run Code Online (Sandbox Code Playgroud)
首先,我假设您正在使用Sitecore.Web.UI.HtmlControls中的Sitecore Combobox(而不是Telerik控件)?
看着Reflector,它最终会做这样的事情:
foreach (Control control in this.Controls)
{
if (control is ListItem)
{
list.Add(control);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我希望你需要通过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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |