EPiServer CMS 6 - custom property with radiobuttonlist

A simple class for using a radiobuttonlist in a custom property in EPiserver CMS 6.
[Serializable]
    [PageDefinitionTypePlugIn(DisplayName = "Traffic status")]
    public class TrafficStatusProperty : EPiServer.Core.PropertyString
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return new TrafficStatusPropertyType();
        }

        public class TrafficStatusPropertyType : EPiServer.Web.PropertyControls.PropertyStringControl
        {
            RadioButtonList inputControl;

            protected override void SetupEditControls()
            {
                base.SetupEditControls();

                TextBox ctrl = this.EditControl;
                ctrl.Attributes.Add("style", "display:none");

                inputControl = new RadioButtonList();
          
                inputControl.Items.Add(new ListItem(Constants.STATUSNAME_GOOD));
                inputControl.Items.Add(new ListItem(Constants.STATUSNAME_MINOR));
                inputControl.Items.Add(new ListItem(Constants.STATUSTEXT_MAJOR));
                inputControl.SelectedValue = this.PropertyData.Value as string;

                this.EditControl.Parent.Controls.Add(inputControl);
            }

            public override void ApplyEditChanges()
            {
                if (!String.IsNullOrEmpty(inputControl.SelectedItem.Value))
                {
                    SetValue(inputControl.SelectedItem.Value);
                }
            } 
        }
    }

1 kommentar:

  1. In case of overriding SetupEditControls and hiding the textbox control, you could override CreateEditControls

    /Alf

    SvaraRadera