Wednesday 10 July 2013

Umbraco Dropdown Multiple(listbox) DataType Pre Values - How to get them

Its really simple, just do the following to bind it to your listbox: XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(1092); preValueRootElementIterator.MoveNext(); //move to first XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", ""); ListItemCollection categoryListItems = new ListItemCollection(); while (preValueIterator.MoveNext()) { categoryListItems.Add(new ListItem(" " + preValueIterator.Current.Value, preValueIterator.Current.GetAttribute("id", ""))); } //Bind data to the list eventscoveredListBox.DataSource = categoryListItems; eventscoveredListBox.DataTextField = "Text"; eventscoveredListBox.DataValueField = "Value"; eventscoveredListBox.DataBind(); You can find the id from going into the cms and passing the mouse over the node of the data type you want, put that node id in and your good to go.

No comments: