Checkbox Properties

Checkbox Properties

Checkbox Fields

  • Store field values of 1 as raw text when checkbox is selected
  • Use Checked property to determine if Checkbox is checked
  • Supported by Sitecore.Data.Fields.CheckboxField class in Sitecore API
  • There is no Sitecore web control for declarative markup of this field
  • Not supported by FieldRenderer.Render() method or FieldRenderer control
  • Does not natively support displaying field values in the Page Editor

Controls featured in this example:

  • Sitecore Web Control
  • XSLT Rendering

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.CheckboxField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Checkbox Properties C# Web Control Code

//get Simple Fields metadata item from context database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{EC44470F-FF45-4023-95C2-EC886FD33D0C}");
if (item == null) return;
Sitecore.Data.Fields.CheckboxField cbFld = item.Fields["example checkbox"];
if (cbFld == 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}", "Field", cbFld.InnerField.DisplayName);
output.RenderEndTag(); //P

output.Write("Checked? " + "<b>" + cbFld.Checked.ToString() + "</b><br/>"); 
output.Write("Can Read? " + "<b>" + cbFld.InnerField.CanRead.ToString() + "</b><br/>"); 
output.Write("Can Write? " + "<b>" + cbFld.InnerField.CanWrite.ToString() + "</b><br/>"); 
output.Write("Contains Standard Value? " + "<b>" + cbFld.InnerField.ContainsStandardValue.ToString() + "</b><br/>"); 
output.Write("Definition: " + "<b>" + cbFld.InnerField.Definition.Name + "</b><br/>"); 
output.Write("Description: " + "<b>" + cbFld.InnerField.Description + "</b><br/>"); 
output.Write("Display Name: " + "<b>" + cbFld.InnerField.DisplayName + "</b><br/>"); 
output.Write("Has Blob Stream? " + "<b>" + cbFld.InnerField.HasBlobStream.ToString() + "</b><br/>"); 
output.Write("Has Value? " + "<b>" + cbFld.InnerField.HasValue.ToString() + "</b><br/>"); 
output.Write("ID: " + "<b>" + cbFld.InnerField.ID.ToString() + "</b><br/>"); 
output.Write("Contains Inherited Value? " + "<b>" + cbFld.InnerField.InheritedValue + "</b><br/>"); 
output.Write("Is Blob Field? " + "<b>" + cbFld.InnerField.IsBlobField.ToString() + "</b><br/>"); 
output.Write("Has Been Modified? " + "<b>" + cbFld.InnerField.IsModified.ToString() + "</b><br/>"); 
output.Write("Key: " + "<b>" + cbFld.InnerField.Key + "</b><br/>"); 
output.Write("Language: " + "<b>" + cbFld.InnerField.Language.Name + "</b><br/>"); 
output.Write("Name: " + "<b>" + cbFld.InnerField.Name + "</b><br/>"); 
output.Write("Reset Blank On? " + "<b>" + cbFld.InnerField.ResetBlank.ToString() + "</b><br/>"); 
output.Write("Section Name: " + "<b>" + cbFld.InnerField.Section + "</b><br/>"); 
output.Write("Sort Order: " + "<b>" + cbFld.InnerField.Sortorder.ToString() + "</b><br/>"); 
output.Write("Shared? " + "<b>" + cbFld.InnerField.Shared.ToString() + "</b><br/>"); 
output.Write("Source: " + "<b>" + cbFld.InnerField.Source + "</b><br/>"); 
output.Write("Title: " + "<b>" + cbFld.InnerField.Title + "</b><br/>"); 
output.Write("Tooltip: " + "<b>" + cbFld.InnerField.ToolTip + "</b><br/>"); 
output.Write("Translatable? " + "<b>" + cbFld.InnerField.Translatable.ToString() + "</b><br/>"); 
output.Write("Type: " + "<b>" + cbFld.InnerField.Type + "</b><br/>"); 
output.Write("Type Key: " + "<b>" + cbFld.InnerField.TypeKey + "</b><br/>"); 
output.Write("Unversioned? " + "<b>" + cbFld.InnerField.Unversioned.ToString() + "</b><br/>"); 
output.Write("Validation Regex: " + "<b>" + cbFld.InnerField.Validation + "</b><br/>"); 
output.Write("Validation Message: " + "<b>" + cbFld.InnerField.ValidationText + "</b><br/>"); 
output.Write("Value: " + "<b>" + cbFld.InnerField.Value + "</b>");

output.RenderEndTag(); //Div


Checkbox Properties C# Web Control Output

Checked? True
Can Read? True
Can Write? True
Contains Standard Value? False
Definition: Example Checkbox
Description: 
Display Name: Example Checkbox
Has Blob Stream? False
Has Value? True
ID: {38565018-85B3-462F-9D13-96A1A99538E0}
Contains Inherited Value? 1
Is Blob Field? False
Has Been Modified? False
Key: example checkbox
Language: en
Name: Example Checkbox
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 100
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? False
Type: Checkbox
Type Key: checkbox
Unversioned? False
Validation Regex: 
Validation Message: 
Value: 1