You should be able to get at the dropdown text value by using the Node.GetProperty() as it's the text value that's pushed to the XML, whilst the database stores the associated ID - hence the Document.GetProperty returns this.
It's also possible to get the text value from the Id, via the umbraco.cms.businesslogic.PreValues object. I've not tested the following, but hopefully should point you in the right direction:
int dataTypeId = ??; int dropDownId = ??; string dropDownText = string.Empty;
Apologies for dragging up an old thread, I also have this issue. I have tried every combo of the dropdown list options (publishing keys, storing as nvarchar, int etc) but it always returns the ID (dropdown key) as a string, rather than the value. I have followed Calvin's advice and it works (thanks mate!) but it seems like a palaver to have to follow the below process:
Convert string ID to int and ensure it is valid int.
Utilise the umbraco.library.GetPreValueAsString(int Id) method to return the dropdown value as a string.
I have no need of the ID on the site so it seems daft you cannot set it to output the value by default. FYI I am using this datatype as a property of a member type, I have not checked if it is the same used with a doctype.
Document.GetProperty on dropdown datatype
Hi All;
I am trying to get the text value of a dropdown list from the API and I am seriously struggling.
This is what I have at the moment:
This returns a string representation of the id for the prevalue.
What I want is the text for that pre value.
Thanks in advance for the help.
Jim
Nobody knows?
I'm stuck with this problem as well! :/
Hi Patrik,
You should be able to get at the dropdown text value by using the Node.GetProperty() as it's the text value that's pushed to the XML, whilst the database stores the associated ID - hence the Document.GetProperty returns this.
It's also possible to get the text value from the Id, via the umbraco.cms.businesslogic.PreValues object. I've not tested the following, but hopefully should point you in the right direction:
Cheers,
Hendy
Or you can try: umbraco.library:GetPreValueAsString(int Id);
Thanks alot guys, solved my issue!
Hi Calvin,
That's a much better / simpler answer :)
Apologies for dragging up an old thread, I also have this issue. I have tried every combo of the dropdown list options (publishing keys, storing as nvarchar, int etc) but it always returns the ID (dropdown key) as a string, rather than the value. I have followed Calvin's advice and it works (thanks mate!) but it seems like a palaver to have to follow the below process:
I have no need of the ID on the site so it seems daft you cannot set it to output the value by default. FYI I am using this datatype as a property of a member type, I have not checked if it is the same used with a doctype.
is working on a reply...