tags:

views:

169

answers:

2

I have a property in umbraco that uses a dropdown data type with a set of prevalues that you can select from.

How do I retreive a list of all the possible prevalues that are in this drop down list?

A: 

There's a helper method in umbraco.library that does that.

From xslt:

<xsl:variable name="prevalues" select="umbraco.library:GetPreValues(1234)" />

From code:

using umbraco;
XPathNodeIterator prevalues = library.GetPrevalues(1234);

Replace 1234 with the id of your datatype (You can see it in the bottom of your browser when hovering your mouse over the datatype in the developers section)

Regards
Jesper Hauge

Hauge
A: 

Here is the code that I use in one of my Umbraco datatypes to get a DropDownList containing all possible prevalues:

var prevalues = PreValues.GetPreValues(dataTypeDefinitionId);
DropDownList ddl = new DropDownList();

if (prevalues.Count > 0)
{
    for (int i = 0; i < prevalues.Count; i++)
    {
        var prevalue = (PreValue)prevalues[i];
        if (!String.IsNullOrEmpty(prevalue.Value))
        {
            ddl.Items.Add(new ListItem(prevalue.Value, prevalue.DataTypeId.ToString()));
        }
    }
}

Replace dataTypeDefinitionId with the id of your datatype.

azzlack