TreelistEx Properties

TreelistEx Properties

Treelist-Ex 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

TreelistEx Guidelines

  • Use a parameterized datasource to restrict the display of TreelistEx fields so that only appropriate items are selectable
  • Use TreelistEx instead of Treelist when displaying large tree hierarchies
  • More efficient than Treelist because TreelistEx only computes the tree when the Edit link is clicked but a Treelist computes it every time it is rendered

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 

TreelistEx 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 tleFld = item.Fields["example treelistex"];
if (tleFld == 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", tleFld.InnerField.DisplayName);
output.RenderEndTag(); //P

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

output.RenderEndTag(); //Div


TreelistEx Properties C# Web Control Output

Can Read? True
Can Write? True
Contains Standard Value? True
Definition: Example TreelistEx
Description: 
Display Name: Example TreelistEx
Has Blob Stream? False
Has Value? False
ID: {B79791FA-118F-459C-A4BD-E69E78A7E9E2}
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 treelistex
Language: en
Name: Example TreelistEx
Reset Blank On? False
Section Name: List Fields
Sort Order: 700
Shared? False
Source: /sitecore/content/Home/ContentAuthors/ContentItems
Title: 
Tooltip: 
Translatable? False
Type: TreelistEx
Type Key: treelistex
Unversioned? False
Validation Regex: 
Validation Message: 
Value: {C32E8A24-3230-46DC-8E82-F9B7014D51C7}|{4902CD3D-2A63-45B8-A7E4-0054DE22D19E}|{48C03219-6A8C-4BC0-A081-B522016AA9C7}

Sources