How to Create a Custom DropDownList

To create a custom DropDownList to be used in Edit Mode start with creating a Custom Property.

  1. Right-click the project root node and select Add -> New Item...
  2. Select the EPiServer Node
  3. Choose Custom Property and type a name for the property
  4. In the "Create Custom Property" dialog that follows, select Derived and choose Longstring as the parent type (also make sure that "Create an associated Control used for rendering the custom property" is checked)
At this point we have a control ready to be manipulated. Open the control source (if we named our property CustomProp, the control would be CustomPropControl.cs)

Add a DropDownList instance to your class.

CopyC#
System.Web.UI.WebControls.DropDownList _DropDown = new System.Web.UI.WebControls.DropDownList();

This instance will be used to manipulate your controls rendering and data.

To make this control be the one rendered, override the CreateEditControls method and add the DropDownList instance to the control set.

CopyC#
public override void CreateEditControls()
{
    _DropDown.Items.Add("An item");
    this.ApplyControlAttributes(_DropDown);
    Controls.Add(_DropDown);
}
To make sure any changes made to your control data in edit mode is saved, you need to override the ApplyEditChanges method.

The control is now ready to be added to and used in EPiServer templates in Edit Mode.


Additional Information

How to Create a Custom Property
Stylesheet Picker in Edit Mode