Hi all,
I found this topic here - https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2014/9/Setting-a-ISelectItem-as-selected/ - but none of the solutions solves my problem.
I have this property on a page, which uses custom Selection Factory.
And I want to set initial value and display it's placeholder (in admin view, under "All properties" view while creating new page) here in a select box. I do it like this:
// CustomSelectionFactory.cs:
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
List<SelectItem> result = new List<SelectItem>()
{
new SelectItem() { Text = "All", Value = null }
};
List<CustomSelectItem> customSelectItems = new List<CustomSelectItem>();
switch (metadata.PropertyName)
{
case "DocumentCountry":
customSelectItems = Api.GetCustomSelectItems(1).Result;
break;
case "DocumentLanguage":
customSelectItems = Api.GetCustomSelectItems(2).Result;
result.RemoveAll(x => x.Text == "All");
metadata.InitialValue = "1";
break;
}
foreach (CustomSelectItems customSelectItem in customSelectItems)
{
result.Add(new SelectItem()
{
Text = customSelectItem .Name,
Value = customSelectItem .Id.ToString()
});
}
return result;
}
// CustomPage.cs
[Display(Name = "Document Country")]
[SelectOne(SelectionFactoryType = typeof(CustomSelectionFactory))]
public virtual string DocumentCountry { get; set; }
[Display(Name = "Document Language")]
[SelectOne(SelectionFactoryType = typeof(CustomSelectionFactory))]
public virtual string DocumentLanguage { get; set; }
Help appreciated!