Computer Magic Logo
Dropdown list multiple

Wednesday, October 26, 2016

Published by Aristotelis Pitaridis

In order to create a Dropdown list multiple we must create our own data type that contains the options of the list. To achieve this we right click on the tree node Data Types of the Developers section to display the node’s commands.

From the commands panel we press on the Create command and the new data type creation form will appear on the screen. 

In the name textbox we type the name of the new data type. From the Property editor dropdown list control we select the Dropdown list multiple option to inform the system that the new data type will be a Dropdown list multiple. 

For each of the options that we want to add in the Dropdown list multiple we type the value in the Add prevalue text box and we click the Add button in order to submit the value.

When we finish with all the options we press the Save button to complete the creation of the new property. Now we can go to the General properties tab of a Document Type to use the new property. 

The My Dropdown List multiple property has the following appearance when we edit the document:

The selected values stored by the system is a string which contains all the values selected by the user separated by a comma. In order to read the value as a strongly typed object we use the following code:

@{
    if (Model.Content.HasValue("myDropdownListMultiple"))
    {
        foreach (var item in Model.Content.GetPropertyValue<string>("myDropdownListMultiple").Split(','))
        {
            <p>@item</p>
        }
    }
}

In order to read the value using dynamic properties we use the following code:

@{
    if (CurrentPage.HasValue("myDropdownListMultiple"))
    {
        foreach (var item in CurrentPage.myDropdownListMultiple.Split(','))
        {
            <p>@item</p>
        }
    }
}