I have added a few prevalues to a dropdown-list. When Im trying to get the value of a property that uses my dropdownlist-data-type I keep getting the "key" of the preValue as the value of the property.. but thats not what Im after.. I need and want to get the actuallt prevalue-string that I entered as my prevalue..
Any ideas?
Oh and btw.. I need to do it using C#..
EDIT
This is what I have tried so far.. and it sort of works.. but It retrives a list of lists that I cant do any quering against..
PreValues.GetPreValues(new Document(statistic.ParentId,true).getProperty("identifier").PropertyType.DataTypeDefinition.DataType.DataTypeDefinitionId).Values
I am using below approch to get dropdown list value as text and id
// Node ID of content node in which dropdown has been used
int NodeIdOfContent = 1111;
Document docMfsFeedSettings = new Document(NodeIdOfContent);
int preValueID = docMfsFeedSettings.getProperty("dropDownAliasName").Value)
// Retrieve Text value
string textValue = umbraco.library.GetPreValueAsString(
Convert.ToInt32(docMfsFeedSettings.getProperty("dropDownAliasName").Value));
It's kind of a mess, but using the PreValues object here's what you would do to get an IEnumerable of just the values:
...
int id = statistic.ParentId;
var node = new Document(id, true);
var property = node.getProperty("dropdown");
var dataTypeDefinitionId = property.PropertyType.DataTypeDefinition.DataType.DataTypeDefinitionId;
// Cast the SortedList to an IEnumerable of DictionaryEntry and then
// select the PreValue objects from it:
var preValues = PreValues.GetPreValues(dataTypeDefinitionId)
.Cast<DictionaryEntry>()
.Select(d => d.Value as PreValue);
// Select just the values from the PreValue objects:
var values = preValues.Select(p => p.Value);
Another approach would be to use the umbraco.library.GetPrevalues(int id)
method. However both approaches are messy in their own ways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With