Get Blank Fields

Get Blank Fields

Testing Blank Fields

  • Display the field value if it exists or if the user is in the Edit Mode of the Page Editor
  • Specify the name of the field in single quotes
  • XSLT Code Example

  • <xsl:if test="(sc:fld('fieldname',.)!='') or (sc:pageMode()/pageEditor/edit)">
  • Controls featured in this example:

  • Sitecore Web Control
  • Classes featured in this example:

  • Sitecore.Collections.FieldCollection
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Items.Item
  • System.String
  • C# Web Control Code

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

    item.Fields.ReadAll();
    Sitecore.Collections.FieldCollection fields = item.Fields;
    if (fields == 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);
    //using &#58; for colon and &#63; for question mark and &#160; for space
    output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
    output.RenderEndTag(); //P

    output.Write("<br/>");
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Border, "0");
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Cellpadding, "3");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Table);
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Thead);
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "right");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
    output.Write("Field Name");
    output.RenderEndTag(); //Th
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
    output.Write("Empty String");
    output.RenderEndTag(); //Th
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
    output.Write("Not HasValue");
    output.RenderEndTag(); //Th
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
    output.Write("Is Null or Empty");
    output.RenderEndTag(); //Th
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
    output.Write("Null");
    output.RenderEndTag(); //Th
    output.RenderEndTag(); //Thead
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tbody);
     
    //using &#9746; for checked box and &#9744; for unchecked box
    foreach (Sitecore.Data.Fields.Field field in fields)
    {
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tr);
        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "right");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
        output.Write("{0}", field.DisplayName);
        output.RenderEndTag(); //Td

        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
        if (field.Value.ToString() == System.String.Empty)
            output.Write("{0}", "&#9746;");
        else
            output.Write("{0}", "&#9744;");
        output.RenderEndTag(); //Td

        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
        if (!field.HasValue)
            output.Write("{0}", "&#9746;");
        else
            output.Write("{0}", "&#9744;");
        output.RenderEndTag(); //Td

        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
        if (System.String.IsNullOrEmpty(field.Value.ToString()))
            output.Write("{0}", "&#9746;");
        else
            output.Write("{0}", "&#9744;");
        output.RenderEndTag(); //Td

        output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "center");
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
        if(field == null)
            output.Write("{0}", "&#9746;");
        else
            output.Write("{0}", "&#9744;");
        output.RenderEndTag(); //Td
            
        output.RenderEndTag(); //Tr
    }
    output.RenderEndTag(); //Tbody
    output.RenderEndTag(); //Table
    output.RenderEndTag(); //Div


    C# Web Control Real-time Output

    Item: Get Blank Fields


    Field Name Empty String Not HasValue Is Null or Empty Null
    Breadcrumb Title
    Archive Version date
    Updated
    Created
    Help link
    Archive date
    Ribbon
    Reminder text
    Publishing targets
    XSLT Demo
    Workflow
    Read Only
    Created by
    Short description
    Validation Bar Validation Rules
    Lock
    CSharp Web Control Code
    Hidden
    Workflow Validation Rules
    Insert Options
    Long description
    Info
    Suppressed Validation Rules
    Controller
    Menu Tooltip
    Style
    Renderings
    Sources
    Sortorder
    Title
    Renderers
    Thumbnail
    Display name
    Default workflow
    Valid to
    Unpublish
    Tracking
    Menu Title
    Page Level Test Set
    Publish
    XSLT Rendering Code
    Sublayout Demo
    __Standard values
    Editor
    Revision
    Skin
    Reminder date
    Web Control Demo
    QR Code
    Validation Button Validation Rules
    __Source
    __Preview
    Icon
    Tiny URL
    CSharp User Control Code
    Owner
    Editors
    Related Topics
    Image
    Quick Action Bar Validation Rules
    Hide version
    Never publish
    Insert Rules
    Valid from
    Controller Action
    State
    Security
    Reminder recipients
    Theme
    Abstract
    Context Menu
    Presets
    Updated by
    __Originator
    Subitems Sorting







































































    Sources