
In an ongoing project I am working on I needed to adapt a custom user control that was being used as a DataType in Umbraco. I needed to locate the nearest node that had a specific property set and default the selected value of my control to the value of the property in the parent document.
Here is the final piece of code:
//- Get the current document as our starting point
Document currentDoc = new Document(Convert.ToInt32(Request.QueryString["id"]));
//- Climb the tree looking for a parent node with the property set
while (currentDoc.getProperty(“myProperty”) == null)
{
currentDoc = new Document(currentDoc.Parent.Id);
}
//- Set the value in the list if it exists
if (this.myDropDownList.Items.FindByValue(currentDoc.getProperty(“myProperty”).Value.ToString()) != null)
{
this.myDropDownList.Items.FindByValue(currentDoc.getProperty(“myProperty”).Value.ToString()).Selected = true;
this.myDropDownList.Enabled = false; //-Disable the control so the branch can’t be changed
}
Thanks again to Tim Geyssens for the tip that led me to my final solution.
Related Posts
- Umbraco : No node exists with id ’1040′
- C# Utility method to populate list controls with world currencies
- C# Utility method to populate list controls with all countries as given in ISO 3166-1
- Remember to use ValidationGroup in Umbraco Dashboard User Controls
- The Association of Women in Property
Related posts brought to you by Yet Another Related Posts Plugin.



One Response
Hi there, I’m looking for a certified Umbraco developer to help me with a website build. Would you be interested in finding out more? I can’t see a contact email on your site anywhere, could you drop me a line if you’re interested? Thanks!