Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    Jul 12, 2015 @ 14:50
    Ayo Adesina
    0

    How to get the String value of a Umbraco.DropDown

    Im trying to get the value that was selected in the back office, the filed is a Umbraco.DropDown which was datatype defined in the developer section

    private void ContentServiceSaved(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
            {
    
                var cs = new ContentService();
                foreach (var myNode in e.SavedEntities.Where(x => x.HasProperty("myProperty")))
                {
       var x = myNode.GetValue("myOtherProperty");
    // x ends up being a number 55 I want the drop down string  value
    }
    
  • Ayo Adesina 445 posts 1059 karma points
    Jul 12, 2015 @ 15:05
    Ayo Adesina
    1

    This worked for me :-)

    String selectedTextVal = umbraco.library.GetPreValueAsString(int.Parse(myNode.GetValue("myOtherProperty").ToString()));
    
  • Kyle Weems 42 posts 296 karma points MVP 8x c-trib
    Jul 27, 2015 @ 16:40
    Kyle Weems
    0

    For those trying to do this in Umbraco 7, I had the following solution. (Spread out into multiple lines for readability).

    var propertyValue = myNode.getPropertyValue("myOtherProperty").ToString();
    var propertyIntValue = int.Parse(propertyValue);
    var selectedTextValue = Umbraco.GetPreValueAsString(propertyIntValue);
    

    There might be a cleaner way to do it, but this gets me the desired string value for a dropdown or radio button list data type.

  • Aki 43 posts 214 karma points
    Oct 27, 2017 @ 08:21
    Aki
    1

    you could do it like this is Umbraco 7

    var selectedTextValue = umbraco.library.GetPreValueAsString(myNode.getValue<int>("myOtherProperty"));
    
  • Ajju 25 posts 148 karma points
    Feb 13, 2018 @ 10:04
    Ajju
    0

    Hello Aki,

    I would like to list in frontend, Dropdown prevalues added in backoffice.

    I hope what you have give, is for the selected item

Please Sign in or register to post replies

Write your reply to:

Draft