Bind Items From ChoiceField
We added field to user profile, Gender, that has three items. We would like to retrieve all the items from this field then bind those to a control. How can we achieve this?
Thank you
Any idea how to do this? We understand that there's only three items that we're expecting from this and we can hard code them instead of doing a retrieve. But we would like to know if this is possible for it might be useful in other scenarios.
Thank you
This is how we got it to work. The code still need some improvement like null checks but you'll see the idea here:
private void BindDropdownList()
string viewControlName = "ProfileType_SitefinityProfile";
string viewName = "ViewFrontendCreate";
string fieldName = "Gender";
ContentViewControlElement element = Config.Get<
ContentViewConfig
>().ContentViewControls[viewControlName];
DetailFormViewDefinition detail = (DetailFormViewDefinition)element.Views[viewName].GetDefinition();
ChoiceFieldDefinition genderField = (ChoiceFieldDefinition)detail.Sections[0].Fields.Where(f => f.FieldName == "Gender").FirstOrDefault();