Treelist Properties

Treelist Properties

Treelist Fields

  • Store selected field values as a pipe-separated list of GUIDs
  • There is no web control for declarative markup
  • Not natively supported by the Page Editor for displaying field values
  • Not supported by FieldRenderer.Render() method or FieldRenderer control
  • Supported by Sitecore.Data.Fields.MultilistField class in Sitecore API
  • Use GetItems() method to retrieve an item array
  • Not supported by Sitecore Query or Fast Query

Treelist Guidelines

  • Use a parameterized datasource to restrict the display of Treelist fields so that only appropriate items are selectable


Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.MultilistField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Treelist Properties C# Web Control Code

//get List Fields metadata item from context database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{7246223A-BFB0-41F9-8A91-1E7D931CDC43}");
if (item == null) return;

Sitecore.Data.Fields.MultilistField tlFld = item.Fields["example treelist"];
if (tlFld == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and   for space
output.Write("{0}: {1}", "Field", tlFld.InnerField.DisplayName);
output.RenderEndTag(); //P

output.Write("Can Read? " + "<b>" + tlFld.InnerField.CanRead.ToString() + "</b><br/>"); 
output.Write("Can Write? " + "<b>" + tlFld.InnerField.CanWrite.ToString() + "</b><br/>"); 
output.Write("Contains Standard Value? " + "<b>" + tlFld.InnerField.ContainsStandardValue.ToString() + "</b><br/>"); 
output.Write("Definition: " + "<b>" + tlFld.InnerField.Definition.Name + "</b><br/>"); 
output.Write("Description: " + "<b>" + tlFld.InnerField.Description + "</b><br/>"); 
output.Write("Display Name: " + "<b>" + tlFld.InnerField.DisplayName + "</b><br/>"); 
output.Write("Has Blob Stream? " + "<b>" + tlFld.InnerField.HasBlobStream.ToString() + "</b><br/>"); 
output.Write("Has Value? " + "<b>" + tlFld.InnerField.HasValue.ToString() + "</b><br/>"); 
output.Write("ID: " + "<b>" + tlFld.InnerField.ID.ToString() + "</b><br/>"); 
output.Write("Contains Inherited Value? " + "<b>" + tlFld.InnerField.InheritedValue + "</b><br/>"); 
output.Write("Is Blob Field? " + "<b>" + tlFld.InnerField.IsBlobField.ToString() + "</b><br/>"); 
output.Write("Has Been Modified? " + "<b>" + tlFld.InnerField.IsModified.ToString() + "</b><br/>"); 
output.Write("Key: " + "<b>" + tlFld.InnerField.Key + "</b><br/>"); 
output.Write("Language: " + "<b>" + tlFld.InnerField.Language.Name + "</b><br/>"); 
output.Write("Name: " + "<b>" + tlFld.InnerField.Name + "</b><br/>"); 
output.Write("Reset Blank On? " + "<b>" + tlFld.InnerField.ResetBlank.ToString() + "</b><br/>"); 
output.Write("Section Name: " + "<b>" + tlFld.InnerField.Section + "</b><br/>"); 
output.Write("Sort Order: " + "<b>" + tlFld.InnerField.Sortorder.ToString() + "</b><br/>"); 
output.Write("Shared? " + "<b>" + tlFld.InnerField.Shared.ToString() + "</b><br/>"); 
output.Write("Source: " + "<b>" + tlFld.InnerField.Source + "</b><br/>"); 
output.Write("Title: " + "<b>" + tlFld.InnerField.Title + "</b><br/>"); 
output.Write("Tooltip: " + "<b>" + tlFld.InnerField.ToolTip + "</b><br/>"); 
output.Write("Translatable? " + "<b>" + tlFld.InnerField.Translatable.ToString() + "</b><br/>"); 
output.Write("Type: " + "<b>" + tlFld.InnerField.Type + "</b><br/>"); 
output.Write("Type Key: " + "<b>" + tlFld.InnerField.TypeKey + "</b><br/>"); 
output.Write("Unversioned? " + "<b>" + tlFld.InnerField.Unversioned.ToString() + "</b><br/>"); 
output.Write("Validation Regex: " + "<b>" + tlFld.InnerField.Validation + "</b><br/>"); 
output.Write("Validation Message: " + "<b>" + tlFld.InnerField.ValidationText + "</b><br/>"); 
output.Write("Value: " + "<b>" + tlFld.InnerField.Value + "</b>");;

output.RenderEndTag(); //Div


Treelist Properties C# Web Control Output

Can Read? True
Can Write? True
Contains Standard Value? True
Definition: Example Treelist
Description: 
Display Name: Example Treelist
Has Blob Stream? False
Has Value? False
ID: {0F3D8A5A-CAAC-4BD6-BA49-E88290073A85}
Contains Inherited Value? {C32E8A24-3230-46DC-8E82-F9B7014D51C7}|{4902CD3D-2A63-45B8-A7E4-0054DE22D19E}|{48C03219-6A8C-4BC0-A081-B522016AA9C7}
Is Blob Field? False
Has Been Modified? False
Key: example treelist
Language: en
Name: Example Treelist
Reset Blank On? False
Section Name: List Fields
Sort Order: 600
Shared? False
Source: /sitecore/content/Home/ContentAuthors/ContentItems
Title: 
Tooltip: 
Translatable? False
Type: Treelist
Type Key: treelist
Unversioned? False
Validation Regex: 
Validation Message: 
Value: {C32E8A24-3230-46DC-8E82-F9B7014D51C7}|{4902CD3D-2A63-45B8-A7E4-0054DE22D19E}|{48C03219-6A8C-4BC0-A081-B522016AA9C7}

Sources