Try our conversational search powered by Generative AI!

Setting a ISelectItem as selected



I have made a EditorDescriptor that renders a CheckBoxList. Is it possible to set some of the ISelectItems returned by the ISelectionFactory as selected? I can only set Text and Value, but it would be nice to set some of the items as selected as well. Does anyone know if this is possible?


Sep 23, 2014 15:47


Not sure if you can do this globally in your editor. But you can set the default value in your content type:

public override void SetDefaultValues(ContentType contentType)

    YourProperty = "TheDefaultValue",
Sep 24, 2014 3:36


SetDefaultValues vil not work for me. I want to check and set the value every time the property is rendered in edit mode.

Sep 24, 2014 12:30

The ExtendedMetadata object that is given as argument to the GetSelections-method in a selectionfactory has an InitialValue property you can use. such as this:

public IEnumerable GetSelections(ExtendedMetadata metadata)
            var list = new List
                new SelectItem {Text = "test", Value = "val1"},
                new SelectItem {Text = "test2", Value = "val2"}

            metadata.InitialValue = "val2";

            return list;
Sep 24, 2014 13:00

Can I set InitialValue to many values? I have a CheckBoxList so I want to set more than one item as selected

Sep 24, 2014 13:18

I havent tested it personally, but since EPiServer internally stores the property value as a comma separated string, I imagine you could just set the InitialValue as "val1,val2,val3" etc.

Sep 24, 2014 13:30

I tried that, but the values appended to InitialValue was ignored. Any other suggestions? :)

Sep 24, 2014 13:42

Hmm, off the top of my head none that doesnt involve dojo :) Sorry, I'll write here if I figure something out :)

Sep 24, 2014 13:46

When creating the editor interface, a form is created totally unaware of the values. Then it's then bound to the values of the object it should edit. This means that there is no good way or getting an editor in a shape that's different then the actual value of the object, unless you somehow make a custom editor. In the old UI, there was an event to be able to modify the object that was used for editing, for instance creating check boxes that were always in a given state, regardless of the actual backing object (Tweaking the default value of "Mark Page as Changed" is a perfect example of this). This is not possible in the new UI since the object returned are used for the entire UI, not only the form.

As Johan already pointed out, you can set the default values to get this behavior when creating new items. But there is currently no supported way of getting this behavior when editing existing objects except of building your own custom editor. If you really need to impement this, the best way is probably inherriting from the built in editor for check boxes (CheckBoxListEditor) and overriding the _setValueAttr method, copy the code for the base class and tweak this.

Sep 25, 2014 13:47

Hi Linus,

Thanks for your answer! I will try to create a new editor that inherits from the CheckBoxListEditor. If I modify the metadata.InitialValue in my SelectionFactory, will these be passed to the new editor? If not, how will I be able to pass the altered values to my new editor?

Sep 25, 2014 14:08
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.