Filtering Values

Filtering Values

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item

Filtering Values C# Web Control Code

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

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

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "First Ten Descendants with Titles that Contain 'Item'");
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item descendant in descendants)
{
if (descendant.Fields["Title"].Value.Contains("Item"))
{
i++;
output.Write("{0}", "<b>" + descendant.Fields["Title"].Value + "</b><br/>");
if (i >= 10) break;
}
}
output.RenderEndTag(); //Div


Filtering Values C# Web Control Output

Item: Content Display

First Ten Descendants with Titles that Contain 'Item'

Item Attributes
Item Locking
Item Management
Well Known Items
Get Home Item
Get Parent Item
Deleting Child Items
Get Child Items
Get Items Of Type
Using ItemList