Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • J 351 posts 606 karma points
    May 08, 2015 @ 11:33
    J
    0

    Data type with DDL

    Umbraco 6.** - sorry couldnt find a forum for this version.

    I have created a datatype called Colors and added Text and Value as below

    Red 1 Blue 2 Yellow 3 Green 4

    Under Document types i create a new property and set the Type to colors. Create a content page using the doc type above and i can see the colors i added.

    How could i use this data type with a user control dropdown list?

  • Urvish 252 posts 772 karma points
    May 08, 2015 @ 11:49
    Urvish
    0

    Hi J,

    You can get drop down list value by using Prevalues like below.

        List<string> li = new List<string>();
        var values = PreValues.GetPreValues(DataTypeId);
        foreach (DictionaryEntry de in values)
        {
            PreValue pv = (PreValue)de.Value;
    
            // Here you will get id and value of the data type drop down list
            // pv.Id
            // pv.value
        }
    

    Hope this will help you.

    Regards,

    Urvish Mandaliya

  • J 351 posts 606 karma points
    May 08, 2015 @ 17:20
    J
    0

    My code is

            private void BindColors()
        {
            List<string> li = new List<string>();
            var values = PreValues.GetPreValues(1234);
            var ddlColors = (DropDownList)lv.FindControl("ddlColors");
    
            foreach (DictionaryEntry de in values)
            {
                PreValue pv = (PreValue)de.Value;
    
                // Here you will get id and value of the data type drop down list
                ddlColors.DataTextField = pv.Value;
                ddlColors.DataValueField = pv.Id.ToString();
            }
    
            ddlColors.DataSource = values;
            ddlColors.DataBind();
        }
    

    the error message i receive is "DataBinding: 'System.Collections.DictionaryEntry' does not contain a property with the name 'Blue'."? Any thoughts

  • Urvish 252 posts 772 karma points
    May 11, 2015 @ 08:33
    Urvish
    0

    Hi J,

    Can you please check the ID of the data type that it is proper or not?

    And try with the below code.

    private void BindColors()
        {
            List<string> li = new List<string>();
            var values = PreValues.GetPreValues(1234);
            var ddlColors = (DropDownList)lv.FindControl("ddlColors");
    
            foreach (DictionaryEntry de in values)
            {
                    PreValue value = (PreValue)de.Value;
                    ListItem li = new ListItem();
                    li.Text = value.Value;
                    li.Value = value.Id.ToString();
                    ddlColors.Items.Add(li);
            }
    
        }
    

    Hope this will help.

    Regards,

    Urvish Mandaliya

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies