2013-03-07 2 views
1

나는이Sitecore 콤보 상자에 항목을 추가

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

같은 마크 업을 가진 Sitecore 쉬어 UI 마법사를 만드는거야하지만 옆에있는 코드에서 콤보 "브랜드"에 옵션을 추가 할 수있는 방법을 찾을 수 없습니다 . 누구든지 아래 코드를 완료하는 방법을 알고 있습니까?

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

} 

답변

6

첫째을, 나는 (예를 들어 아닌 Telerik 제어)는 Sitecore.Web.UI.HtmlControls에서 Sitecore 콤보 상자를 사용하고 있으리라 믿고있어? ,

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

그래서 나는 당신이 당신의 brandsInSqlDb을 통해 루프를 구축해야합니다 기대하고 있어요하여 ListItem을 인스턴스화하고 브랜드 콤보 상자에 추가 : 리플렉터에서 찾고

는,이 같은 일을 결국

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); 
} 
+0

감사합니다. –

1

같이 .Something은 B (콤보하지 콤보) 소문자한다. 전체 공간은 다음과 같습니다

protected Sitecore.Web.UI.HtmlControls.Combobox Brands; 

은 그럼 당신은 옵션, 예를 추가 할 수 있습니다

ListItem listItem = new ListItem(); 
this.Brands.Controls.Add((System.Web.UI.Control) listItem); 
listItem.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("ListItem"); 
listItem.Header = name; 
listItem.Value = name; 
listItem.Selected = name == selectedName; 
0

방법 나는 1 액세스 페이지에서 Combo 박스 수행 이제

ComboBox comboBox = Page.Controls.FindControl("idOfYourComboBox") as ComboBox 

페이지에서 정의한 컨트롤에 액세스 할 수 있습니다. 지금 할 일은 가치를 부여하는 것입니다 :

foreach (var brand in brandsInSqlDb) 
{ 
    comboBox .Header = brand.Name; // Set the text 
    comboBox .Value = brand.Value; // Set the value 
    Brands.Controls.Add(item); 
} 
관련 문제