Element Values by Example

In this example, color values (blue, green, and orange) are defined in the get_element_values.cs file within from the GetElementValues method. The choice hook applies these values to a page element, in this case a drop-down list, that has an element name match.

Stepping through this example:

  1. In Schema Designer, create a page with a List element.
  2. In the Tag Name field of the new List element, enter ColorChoice.
    The Tag Name value must be identical to the element Name defined in GetElementValues() below.
  3. For the purpose of this example, do not populate the Choices field.
  4. Include the following GetElementValues method to get_element_values.cs in [path-to-cms-site-instance]/site/App_Data/xml/Custom:
    public IEnumerable GetElementValues(string schemaName, string elementName,
    ChoicesProviderOptions options, ISite site)
    if (elementName == "ColorChoice")
    return new[]
    new SelectionChoiceItem {
    Label = "Blue",
    Value = "1"
    new SelectionChoiceItem {
    Label = "Green",
    Value = "2"
    new SelectionChoiceItem {
    Label = "Orange",
    Value = "3"
  5. Create an instance of the new page schema with a List element.
  6. To complete this walk through, verify that this page's drop-down list contains the color choice values defined in GetElementValues().

    Get Values for Drop-down List Example

    The Color Choice enumeration list have been populated by the color items encoded in GetElementValues().