After som searching i found this EPiServer forum thread that show how to create a custom property in CMS 5. Not rocket sience, but I like to have one place to find code samples that will speed up my work. With this new blog I have just such a place
using System;
using System.Collections.Generic;
using System.Text;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.PlugIn;
using EPiServer.Web.PropertyControls;
using System.Web.UI.WebControls;namespace EPiServerDemo.PropertyTypes
{
/// <summary>
/// Custom PropertyData implementation
/// </summary>
[Serializable]
[PageDefinitionTypePlugIn(DisplayName="My demo dropdown")]
public class MyDropDownCore : EPiServer.Core.PropertyString
{
public override IPropertyControl CreatePropertyControl()
{
return new MyDropDownPropType();
}
}
public class MyDropDownPropType : EPiServer.Web.PropertyControls.PropertySelectControlBase
{
protected override void SetupEditControls()
{
base.SetupEditControls();DropDownList inputControl = this.EditControl;
inputControl.Items.Add("Red");
inputControl.Items.Add("Blue");
inputControl.Items.Add("Green");
inputControl.SelectedValue = this.PropertyData.Value as string;
}
}
}

3 comments
Comments feed for this article
15 February, 2008 at 13:52
Reena
Hi
I used your code. but the system dows not recognise DropDownList.
i’ve included this in the Episerver Custom property.
Is there anythin gelse to be done.
19 February, 2008 at 13:25
Jonas Peterson
The DropDownList can be found in the System.Web.UI.WebControls namespace
16 January, 2009 at 11:51
Magnus
I have code very similar to yours, except I derived from EPiServer.Core.PropertyNumber and I populate the dropdown with ListItem value pairs.
When I publish a page the values are saved and all but when I edit an existing page the dropdown controls are not initialized correctly and the page values are not displayed but rather the dropdown control retains the same value as it had when that page type was last saved.
This happens per property. I have four properties of the same type on this page type. The previous (last saved) values are redisplayed on the next edit. I.e. if the properties are set to the values of e.g. 1, 2, 3, 4 respectively, on the next page edit the values are not (as you might have expected) all the same value but rather redisplays as 1, 2, 3, 4.
This perplexes me as I, like you, have the line setting the SelectedValue of teh control.