Using Tables

Using Tables

Controls featured in this example:

  • Sitecore Web Control
  • XSLT Rendering

Classes featured in this example:

  • Sitecore.Collections.ChildList
  • Sitecore.Collections.ChildListOptions
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil

Tables C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

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

Sitecore.Collections.ChildList children = ancestor.GetChildren(Sitecore.Collections.ChildListOptions.None);
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(); //Div

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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Cellpadding, "2");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Table);
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Thead);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Item");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Item ID");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Template Name");
output.RenderEndTag(); //Th
output.RenderEndTag(); //Thead
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tbody);

foreach (Sitecore.Data.Items.Item child in children)
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tr);
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.DisplayName);
    output.RenderEndTag(); //Td

    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.ID.ToString());
    output.RenderEndTag(); //Td

    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.TemplateName.ToLower());
    output.RenderEndTag(); //Td

    output.RenderEndTag(); //Tr
}
output.RenderEndTag(); //Tbody
output.RenderEndTag(); //Table
output.RenderEndTag(); //Div


Tables XSLT Rendering Code

<xsl:variable name="ancestor" select="../.." />
<br/>
<div style="font-weight:bold; width:100%; clear:both"> <br/>
<xsl:value-of select="'XSLT Rendering Real-time Output'"/>
</div>

<div style="font-size:x-small; width:100%; clear:both">
<p><b>Item: <sc:text field="title" select="$sc_item" disable-web-editing="true"/></b></p>

<table cellpadding="2" border="0">

<thead>
   <th align="center"><xsl:value-of select="'Item'"/></th>
   <th align="center"><xsl:value-of select="'Item ID'"/></th>
   <th align="center"><xsl:value-of select="'Template Name'"/></th>
</thead>
    
<tbody>
<xsl:for-each select="$ancestor/item">
   <tr>
      <td><sc:text field="title" select="." disable-web-editing="true" /></td>
      <td><xsl:value-of select="./@id" /></td>
      <td><xsl:value-of select="./@template" /></td>
   </tr> 
</xsl:for-each>
</tbody>

</table> 
</div>


Tables C# Web Control Output

Item Item ID Template Name
Ancestor Axis {DB042F8F-88B2-4A55-A117-9E6185C2F826} tic-permbuilderpage
Descendant Axis {51433033-6CBC-4978-B87B-F5E4ADC73907} tic-permbuilderpage
Field Values {90AA564A-1C1B-4CE0-8B1F-DF2A0A8BB521} tic-permbuilderpage
Icon Management {557148B5-1445-4221-A7C3-D1ED85F96C10} tic-permbuilderpage
Internationalization {B332BA6C-8E93-472C-9DBF-97E97C85663A} tic-permbuilderpage
Item Attributes {D6187B4B-43B7-40E7-98B4-35DFF611272B} tic-permbuilderpage
Item Locking {81183458-A45C-4329-ABFC-44D7CB1BC3F5} tic-permbuilderpage
Item Management {1F49451E-D0A6-4285-BDFF-A7E626CA35E8} tic-permbuilderpage
Link Management {F7853460-7264-40E0-A46B-C0F6DEAA9CEC} tic-permbuilderpage
Sitecore Queries {949E08DB-61D9-4967-9F7F-41FFF3A6031D} tic-permbuilderpage
Well Known Items {AFD0C9B3-7925-4381-9EF6-B0BB0061ED28} tic-permbuilderpage

XSLT Rendering Real-time Output

Item: Using Tables

Item Item ID Template Name
Ancestor Axis {DB042F8F-88B2-4A55-A117-9E6185C2F826} tic-permbuilderpage
Descendant Axis {51433033-6CBC-4978-B87B-F5E4ADC73907} tic-permbuilderpage
Field Values {90AA564A-1C1B-4CE0-8B1F-DF2A0A8BB521} tic-permbuilderpage
Icon Management {557148B5-1445-4221-A7C3-D1ED85F96C10} tic-permbuilderpage
Internationalization {B332BA6C-8E93-472C-9DBF-97E97C85663A} tic-permbuilderpage
Item Attributes {D6187B4B-43B7-40E7-98B4-35DFF611272B} tic-permbuilderpage
Item Locking {81183458-A45C-4329-ABFC-44D7CB1BC3F5} tic-permbuilderpage
Item Management {1F49451E-D0A6-4285-BDFF-A7E626CA35E8} tic-permbuilderpage
Link Management {F7853460-7264-40E0-A46B-C0F6DEAA9CEC} tic-permbuilderpage
Sitecore Queries {949E08DB-61D9-4967-9F7F-41FFF3A6031D} tic-permbuilderpage
Well Known Items {AFD0C9B3-7925-4381-9EF6-B0BB0061ED28} tic-permbuilderpage

Sources