Number Properties

Number Properties

Number Fields

  • Store field values as raw text
  • Supported by <sc:text> web control in declarative markup
  • Field values can be displayed by the FieldRenderer.Render() method and FieldRenderer control
  • Natively supports displaying field values in the Page Editor
  • Sitecore recommends not to use XSL to process Number fields

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Number 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.TextField numFld = item.Fields["example number"];
if (numFld == 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 &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Field", numFld.InnerField.DisplayName);
output.RenderEndTag(); //P

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

output.RenderEndTag(); //Div


Number Properties C# Web Control Output

Can Read? True
Can Write? True
Contains Standard Value? True
Definition: Example Number
Description: 
Display Name: Example Number
Has Blob Stream? False
Has Value? False
ID: {3A29257C-3879-4C46-8A2E-18767C72F6D5}
Contains Inherited Value? 999.97
Is Blob Field? False
Has Been Modified? False
Key: example number
Language: en
Name: Example Number
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 800
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? False
Type: Number
Type Key: number
Unversioned? False
Validation Regex: 
Validation Message: 
Value: 999.97