ComboBoxGroup

in namespace DotVVM.Framework.Controls.Bootstrap

Usage & Scenarios

Represents a group of Label and ComboBox in the Form control.

Sample 1: Basic Usage

The collection of items for selection in the combo box is set with the DataSource property. Item selected by user is then stored in the SelectedValue property binded to a property in viewmodel.

The LabelText property is used to set the label of the ComboBoxGroup control.

<bs:Form>
    <bs:ComboBoxGroup LabelText="Animals" DataSource="{value: Animals}" SelectedValue="{value: SelectedAnimal}" />
</bs:Form>

<span>Selected: {{value: SelectedAnimal}}</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ComboBoxGroup.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string SelectedAnimal { get; set; }
        public string[] Animals { get; set; } = { "Cat", "Dog", "Pig", "Mouse", "Rabbit" };
    }
}

Sample 2: Enabled, Visible and EmptyItemText

The EmptyItemText property is used to set text of an empty item. The empty item has a value of null.

It is also possible to enable / disable the ComboBoxGroup control with the Enabled property.

To show / hide the ComboBoxGroup control the Visible property can be used.

<span>Selected: {{value: SelectedAnimal}}</span>

<bs:Form>
    <bs:ComboBoxGroup LabelText="Enabled" 
                      DataSource="{value: Animals}" 
                      SelectedValue="{value: SelectedAnimal}" 
                      Enabled="{value: TrueValue}" />

    <bs:ComboBoxGroup LabelText="Disabled" 
                      DataSource="{value: Animals}" 
                      SelectedValue="{value: SelectedAnimal}" 
                      Enabled="{value: FalseValue}" />

    <bs:ComboBoxGroup LabelText="Animals" 
                      DataSource="{value: Animals}" 
                      SelectedValue="{value: SelectedAnimal2}" 
                      EmptyItemText="Select..." />
</bs:Form>

<span>Selected: {{value: SelectedAnimal2}}</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ComboBoxGroup.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string SelectedAnimal { get; set; }
        public string SelectedAnimal2 { get; set; }
        public string[] Animals { get; set; } = { "Cat", "Dog", "Pig", "Mouse", "Rabbit" };
        public bool TrueValue { get; set; } = true;
        public bool FalseValue { get; set; } = false;
    }
}

Sample 3: Object Binding

You can also bind the DataSource property to a collection of complex objects. The text which will be then shown inside the combo box for all items is taken from a property of that complex item with name specified in the DisplayMember property. Returned value of selected item is taken from a property of that item with name specified in the ValueMember property.

<bs:Form>
    <bs:ComboBoxGroup DataSource="{value: Items}" 
                      SelectedValue="{value: SelectedItem}" 
                      LabelText="Label" 
                      ValueMember="Id" 
                      DisplayMember="Name" />
</bs:Form>

<span>Selected: {{value: SelectedItem}}</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ComboBoxGroup.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int SelectedItem { get; set; }
        public Item[] Items { get; set; } =
        {
            new Item { Id = 1, Name = "Item 1" },
            new Item { Id = 2, Name = "Item 2" },
            new Item { Id = 3, Name = "Item 3" },
        };
    }

    public class Item
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Sample 4: SelectionChanged event

It is also possible to bind an action to the event when the selected value in the combo box has changed. Use the SelectionChanged property to set a command which will be executed when the event triggers.

<bs:Form>
    <bs:ComboBoxGroup EmptyItemText="Select..." 
                    LabelText="Select prime number" 
                    DataSource="{value: Numbers}" 
                    SelectedValue="{value: SelectedNumber}" 
                    SelectionChanged="{command: SelectionChanged()}" />
</bs:Form>

<span>{{value: Result}}</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ComboBoxGroup.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int SelectedNumber { get; set; }
        public int[] Numbers { get; set; } = { 7, 10, 13, 19 };
        public string Result { get; set; } = "Select something...";

        public void SelectionChanged()
        {
            Result = SelectedNumber != 10 ? "Correct!" : "10 is not a prime number!";
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
null
property icon ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
property icon DataContext Object Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value.
attribute
inner element
static value
bindable
default
null
property icon DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
null
property icon DisplayMember String Gets or sets the name of property in the DataSource collection that will be displayed in the control.
attribute
inner element
static value
bindable
default
property icon EmptyItemText String Gets or sets a text of an empty item. This item is auto-generated and is not part of the DataSource collection. The empty item has a value of null.
attribute
inner element
static value
bindable
default
property icon Enabled Boolean Gets or sets a value indicating whether the control is enabled and can be modified.
attribute
inner element
static value
bindable
default
True
property icon FormContent List<DotvvmControl> Gets or sets the content of the form group.
attribute
inner element
static value
bindable
default
null
property icon ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
null
property icon InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
null
property icon LabelTemplate ITemplate Gets or sets the template of the label area. This property cannot be combined with the LabelText property.
attribute
inner element
static value
bindable
default
null
property icon LabelText String Gets or sets the label text. This property cannot be combined with the LabelTemplate property.
attribute
inner element
static value
bindable
default
null
property icon RenderContentContainers Boolean Gets or sets whether an additional container will be rendered around the content.
attribute
inner element
static value
bindable
default
True
property icon SelectedValue Object Gets or sets the value of the selected item.
attribute
inner element
static value
bindable
default
null
property icon ValueMember String Gets or sets the name of property in the DataSource collection that will be passed to the SelectedValue property when the item is selected.
attribute
inner element
static value
bindable
default
property icon Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon SelectionChanged Command Gets or sets the command that will be triggered when the selection is changed.

HTML produced by the control