Using For Loop

Using For Loop

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Collections.ChildList
  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Using For Loop C# Web Control Code

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

Sitecore.Collections.ChildList children = item.Children;
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);
output.Write("Item: " + item.DisplayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ol);

for (int i = 0; i < children.Count; i++)
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li); 
output.Write("{0}", children[i].Name); 
output.RenderEndTag(); //Li

}
output.RenderEndTag(); //Ol
output.RenderEndTag(); //Div


Using For Loop C# Web Control Output

  1. AncestorAxis
  2. DescendantAxis
  3. FieldValues
  4. IconManagement
  5. Internationalization
  6. ItemAttributes
  7. ItemLocking
  8. ItemManagement
  9. LinkManagement
  10. SitecoreQueries
  11. WellKnownItems