Monday, October 17, 2011

Getting Umbraco radiobutton list values and prevalues

You know how umbraco gives you an int when you're using a radiobutton list. Don't you wish it would give you the value selected in c#... Even possibly the values which are defined so you can check against them?

I discovered a (possibly convoluted) way of getting these. Note: the node object in the example below is of type Document

// get the key values defined in the datatype for property "myProperty"
var keyValues = ((KeyValuePrevalueEditor)node.getProperty("myProperty").PropertyType.DataTypeDefinition.DataType.PrevalueEditor.Editor).PrevaluesAsKeyValuePairList;

// get the value which maps to the int which Umbraco saves when you select the radiobutton
var value = umbraco.library.GetPreValueAsString(int.Parse(node.getProperty("myProperty").Value.ToString()))


Post a Comment