More in this section

Forums / Developing with Sitefinity / Bind Items From ChoiceField

Bind Items From ChoiceField

3 posts, 1 answered
  1. Ernest
    Ernest avatar
    37 posts
    Registered:
    12 Mar 2012
    26 Feb 2013
    Link to this post

    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

  2. Ernest
    Ernest avatar
    37 posts
    Registered:
    12 Mar 2012
    27 Feb 2013
    Link to this post

    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

  3. Ernest
    Ernest avatar
    37 posts
    Registered:
    12 Mar 2012
    12 Mar 2013
    Link to this post
    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();
            }
    Answered
3 posts, 1 answered