I was trying to get some prevalues that I created as a drop down list datatype. I had a look through the example that is on the library section of this website (http://our.umbraco.org/wiki/reference/umbracolibrary/getprevalues) but came across a problem . The XPathNodeIterator doesn't find my prevalues as they don't appear in the xml. I thought they would automatically be put into the xml when you create a datatype.
Thanks for the reply. That's how I tried to do it myself but XPathNodeIterator preValueIterator = umbraco.library.GetPreValues(DataTypeID) doesn't bring anything back. It's looking at the xml rather than the database.
//Bind data to ddllist CategoryDDList.DataSource= categoryListItems; CategoryDDList.DataTextField="Text"; CategoryDDList.DataValueField="Value"; CategoryDDList.DataBind();
Is it possible to get the pre values not using the data type id but name? The reason being is that we have numerous Umbraco databases and if the ID of the data type is out of sync it will not work having directly used the id.
Using GetPreValues
Hi,
I was trying to get some prevalues that I created as a drop down list datatype. I had a look through the example that is on the library section of this website (http://our.umbraco.org/wiki/reference/umbracolibrary/getprevalues) but came across a problem . The XPathNodeIterator doesn't find my prevalues as they don't appear in the xml. I thought they would automatically be put into the xml when you create a datatype.
Any ideas would be very appreciated.
Check out this code I use to build dropdownlists from datatypes. It gets the prevalues from the database, not the XML.
public static HtmlSelect test(int DataTypeID, string defaultValue)
{
HtmlSelect ddl = new HtmlSelect();
if (!string.IsNullOrEmpty(defaultValue))
{
ddl.Items.Add(new ListItem(defaultValue, "0", true));
}
XPathNodeIterator preValueIterator = umbraco.library.GetPreValues(DataTypeID);
preValueIterator.MoveNext();
XPathNodeIterator ValueIterator = preValueIterator.Current.SelectChildren("preValue", "");
while (ValueIterator.MoveNext())
{
if (string.IsNullOrEmpty(umbraco.library.GetDictionaryItem(ValueIterator.Current.Value)))
{
ddl.Items.Add(new ListItem(ValueIterator.Current.Value, ValueIterator.Current.GetAttribute("id", ""), true));
}
else
{
ddl.Items.Add(new ListItem(library.GetDictionaryItem(ValueIterator.Current.Value), ValueIterator.Current.GetAttribute("id", ""), true));
}
}
return ddl;
}
Hope this helps
Thanks for the reply. That's how I tried to do it myself but XPathNodeIterator preValueIterator = umbraco.library.GetPreValues(DataTypeID) doesn't bring anything back. It's looking at the xml rather than the database.
This was how I tried to do it (unsuccessfully)
Got it working, it was my mistake, I had the wrong id in XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(1210);
Yeh, that would do it :)
Is it possible to get the pre values not using the data type id but name? The reason being is that we have numerous Umbraco databases and if the ID of the data type is out of sync it will not work having directly used the id.
I'm afraid not. At least that I know of.
If you do find a way, please share. I have exactly the same situation.
Cheers
I found this code here, which allows you to specify the datatype name and get the ID:
Then you can use this in the iterator code:
~Heather
is working on a reply...