Copied to clipboard

Flag this post as spam?

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


  • Alex 21 posts 41 karma points
    Aug 16, 2010 @ 18:19
    Alex
    0

    Do prevalues have ids?

    I'm using prevalues of a checkbox list data type as categories (for assigning to blog posts). I want to create a page which shows all blog posts that have a certain prevalue attached to them, and don't want to pass the entire prevalue name in the querystring. Do the prevalues have ids? If so how do I get at them?

    Many thanks in advance!

  • Sascha Wolter 615 posts 1101 karma points
    Aug 16, 2010 @ 20:51
    Sascha Wolter
    1

    Hi Alex,

    getting the string value for a prevalue is quite straightforward as the IDs are unique across all prevalues of all datatypes. The other way around though is not that easy because even with one datatype you can add the same value twice, so you have no chance of converting the actual content back to an ID as it would be ambiguous.

    What you could do though is taking care of the duplication thing yourself and writing a custom XsltExtension which will get the prevalues for a specific datatype complete with values and id and then try to match your content to an id. I have once written a web service which did something similar for a specific data type, maybe this will help you further:

                //retrieve all datatypes available
                DataTypeDefinition[] types = DataTypeDefinition.GetAll();

                //loop through the datatypes and extract the pre-values if the smartbite datatype was found
                foreach (DataTypeDefinition type in types) {
                    if (type.Text == "my custom type") {
                        SortedList list = PreValues.GetPreValues(type.Id);

                        foreach (DictionaryEntry o in list) {

                            PreValue v = ((PreValue)o.Value);
                            int id = v.Id;
                            string name = v.Value;
                            //do something with it

                        }
                    }
                }

    Sascha

Please Sign in or register to post replies

Write your reply to:

Draft