• Publisert
  • 1 min

Custom boolean property

As a developer working with dynamic properties, I am sure you have came across the fact that it is not possible to reset or empty an EPiServer boolean dynamic property. This is something I’ve needed several times, so here is a simple sample code to create a custom boolean property.

No changes made from the default EPiServer template

Override CreateEditControls like this:

public override void CreateEditControls()

    DropDownList myList = this.EditControl;
    myList.Items.Add(new ListItem("False", "0"));
    myList.Items.Add(new ListItem("True", "1"));

    //set selected property values
    string val = this.ToString();
    if (val.Length > 0)
      myList.SelectedValue = val;