I was wondering how I would make a html drop down list from the values in a datatype? It needs to have the prevalue as the name and the associated ID number as the value.
This can be achieved with the following code:
@using System.Xml.XPath
@{
XPathNodeIterator iterator = umbraco.library.GetPreValues(1124);
iterator.MoveNext();
XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
}
<select name="codeTheme">
@while (preValues.MoveNext())
{
string preValue = preValues.Current.Value;
string id = preValues.Current.GetAttribute("id", "");
<option value="@id" @(member.GetValue("codeTheme").ToString() == id ? "selected" : "")>@preValue</option>
}
</select>
You just need to change the ID number in the GetPreValues(xxxx)
to the id of the datatype you are targeting. To find this navigate the to datatype in the Umbraco back-end and take the number from the URL.
"codeTheme" needs to be changed to name of the property in the memebership area.