FAQ - Umbraco

Accessing Drop Down Lists Programatically

The code snippets below provide examples for how to programatically access Umbraco data types with pre values, for example the Umbraco drop down list:

Populating a drop down list with pre values

using System.Collections;
using umbraco.cms.businesslogic.datatype;

var values = PreValues.GetPreValues(YOUR_DATA_TYPE_ID_HERE);
foreach (DictionaryEntry de in values) { 
    PreValue value = (PreValue)de.Value; 
    ListItem li = new ListItem(); 
    li.Text = value.Value; 
    li.Value = value.Id.ToString(); 

The above code queries Umbraco for the pre-values for the data type you specify and returns a collection of DictionaryEntry's. We then loop through, adding list items to your drop down list.


Saving the selected value


Simply get the selected item's value using the code above and save it in the node.

If you found this information useful, please share it!

This FAQ was last updated on Wednesday, September 30, 2015

Contact Information

To find out more about Ava solutions you can contact us in a number of ways:
Follow Us...