Copied to clipboard

Flag this post as spam?

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


  • Vlad 4 posts 24 karma points
    Mar 16, 2015 @ 17:24
    Vlad
    0

    List of drop down values with id and sort order (v7.2.2)

    Hello,

    Just wanted to double check the correct way of getting the list of prevalues of a dropdown datatype. So far i have:

    New way i think, i got this though looking at core code on github:

    var dataService = ApplicationContext.Services.DataTypeService;
    var dictionaryDropdownPreValues = dataService.GetPreValuesCollectionByDataTypeId(idOfProperty).PreValuesAsDictionary;
        foreach(KeyValuePair<string, PreValue> preValue in  dictionaryDropdownPreValues){
            @:@preValue.Value.Id : @preValue.Value.Value : @preValue.Value.SortOrder
        }
    

    Old way from a stack overflow article:

    var preValues = PreValues.GetPreValues(idOfProperty).Values;
    var enumerator = preValues.GetEnumerator();
    while (enumerator.MoveNext()){
        var preValueText = ((umbraco.cms.businesslogic.datatype.PreValue)enumerator.Current);
        @:@preValueText.Id : @preValueText.Value : @preValueText.SortOrder
    }
    

    Really old way (?deprecated):

    var preValuesDropdown = uQuery.GetPreValues(idOfProperty);
    foreach(var preValue in preValuesDropdown){
        @:@preValue.Id : @preValue.Value : @preValue.SortOrder <br/>
    }
    

    Am i correct in assuming the first option (using the ApplicationContext.Services.DataTypeService) is the correct way of doing this?

    To give some context, i am doing this because i want to make a few member drop down properties accessible on the member profile page.

Please Sign in or register to post replies

Write your reply to:

Draft