DisplayName Sort

DisplayName Sort

DisplayName

  • An optional property of an item that determines the label to display for the item in the Content Tree
  • Overrides the default display of the item key in the Content Tree

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Comparers.Comparer
  • Sitecore.Data.Comparers.DisplayNameComparer
  • Sitecore.Data.Items.Item
  • System.Array.Sort

DisplayName Sort C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item.Parent;
if (item == null) return;

Sitecore.Data.Items.Item[] children = item.Children.ToArray();
if (children == 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}", "Parent Item", item.DisplayName);
output.RenderEndTag(); //P

Sitecore.Data.Comparers.Comparer compare = new Sitecore.Data.Comparers.DisplayNameComparer(); 
System.Array.Sort(children, compare);

foreach (Sitecore.Data.Items.Item child in children)
{
    output.Write("{0}", child.DisplayName + "<br/>");
}
output.RenderEndTag(); //Div


DisplayName Sort C# Web Control Output

Parent Item: Descendant Axis

ChildList Sort
Children Property
Counting Pages
Deleting Child Items
Descending Sort
DisplayName Sort
Filter Descendants
Filtering Values
Get Child Items
Get Descendants
Get Items Of Type
Linq Filter Sort
Reset Renderings
Using ArrayList
Using ChildList
Using For Loop
Using ItemList
Using Tables
Using ToArray()

Sources