Bind Items From ChoiceField

Posted by Community Admin on 04-Aug-2018 17:39

Bind Items From ChoiceField

All Replies

Posted by Community Admin on 26-Feb-2013 00:00

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

Posted by Community Admin on 27-Feb-2013 00:00

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

Posted by Community Admin on 12-Mar-2013 00:00

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();
        

This thread is closed