Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 394 posts 1477 karma points
    Jan 22, 2015 @ 14:25
    Paul de Quant
    0

    How to get Pre-Value ID's rather than String Names

    Hello,

    I'm trying to find out how to find the Id of a pre-value list selection (in this case a check box list).

    • Id: 1 Value: United Kingdom
    • Id: 2 Value: United States
    • Id: 3 Value: The Netherlands

    I have the check box list (added via contour), which returns the users selection as United Kingdom, United States however I need to find the Id's of the selection, rather than the names.

    I sort of need the reverse of GetPreValueAsString().

    I hope this makes sense and can anyone help.

    Thanks

    Paul

  • Paul de Quant 394 posts 1477 karma points
    Jan 22, 2015 @ 15:09
    Paul de Quant
    100

    While a little bit crude, I have found a way to do this.

    selectedFileCategories is my comma seperated string e.g. United Kingdom, United States

                    XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(1361);
                    preValueRootElementIterator.MoveNext();
    
                    XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
    
                    while (preValueIterator.MoveNext())
                    {
                        if (selectedFileCategories.Contains(preValueIterator.Current.Value))
                        {
                            selectCats += preValueIterator.Current.GetAttribute("id", "") + ",";
                        }
                    }
    

    This will return selectCats as 1,2,3

  • 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