ComboBox

in namespace DotVVM.Bootstrap5.Controls

Renders a Bootstrap select control.

Usage & Scenarios

Extends the builtin ComboBox control to allow sizing.

https://getbootstrap.com/docs/5.2/forms/select/

Sample 1: Basic Usage

To fill combobox vith values use property DataSource and then properties ItemTextBinding, ItemValueBinding and ItemTitleBinding which set text, value and title of combobox items.

To specify currently displayed item use property SelectedValue and set it to index of item.

<bs:ComboBox SelectedValue="{value: SelectedValue}" 
             DataSource="{value: ComboBoxDataSource}" 
             ItemTextBinding="{value: Text}" 
             ItemValueBinding="{value: Value}" 
             ItemTitleBinding="{value: Title}" />

Selected value: {{value:  SelectedValue}}
public class ViewModel : DotvvmViewModelBase
{
    public List<ListItemModel> ComboBoxDataSource { get; set; } = new List<ListItemModel>
            {
                new ListItemModel()  { Value = 1, Text = "Too long text", Title = "Nice title",  },
                new ListItemModel()  { Value = 2, Text = "Text", Title = "Even nicer title" }
            };


    public int SelectedValue { get; set; }

    public class ListItemModel
    {
        public int Value { get; set; }
        public string Text { get; set; }
        public string Title { get; set; }
    }
}

Sample 2: ComboBox Sizing

Use the Size property to set the size of the ComboBox.

    <h5>Default Size</h5>
    <bs:ComboBox SelectedValue="{value: SelectedValue}" 
                 DataSource="{value: ComboBoxDataSource}" 
                 ItemTextBinding="{value: Text}" 
                 ItemValueBinding="{value: Value}" 
                 Size="Default" />
    <h5>Large Size</h5>
    <bs:ComboBox SelectedValue="{value: SelectedValue}" 
                 DataSource="{value: ComboBoxDataSource}" 
                 ItemTextBinding="{value: Text}" 
                 ItemValueBinding="{value: Value}" 
                 Size="Large" />
    <h5>Small Size</h5>
    <bs:ComboBox SelectedValue="{value: SelectedValue}" 
                 DataSource="{value: ComboBoxDataSource}" 
                 ItemTextBinding="{value: Text}" 
                 ItemValueBinding="{value: Value}" 
                 Size="Small" />
public class ViewModel : DotvvmViewModelBase
{
    public List<ListItemModel> ComboBoxDataSource { get; set; } = new List<ListItemModel>
            {
                new ListItemModel()  { Value = 1, Text = "Too long text", Title = "Nice title",  },
                new ListItemModel()  { Value = 2, Text = "Text", Title = "Even nicer title" }
            };


    public int SelectedValue { get; set; }

    public class ListItemModel
    {
        public int Value { get; set; }
        public string Text { get; set; }
        public string Title { get; set; }
    }
}

Sample 3: Empty Item Text

Use property EmptyItemText to specify shown text if no item is selected.

    <bs:ComboBox SelectedValue="{value: null}" 
                 DataSource="{value: ComboBoxDataSource}" 
                 ItemTextBinding="{value: Text}" 
                 ItemValueBinding="{value: Value}" 
                 EmptyItemText="Some Empty Item Text" />
public class ViewModel : DotvvmViewModelBase
{
    public List<ListItemModel> ComboBoxDataSource { get; set; } = new List<ListItemModel>
            {
                new ListItemModel()  { Value = 1, Text = "Too long text", Title = "Nice title",  },
                new ListItemModel()  { Value = 2, Text = "Text", Title = "Even nicer title" }
            };


    public int SelectedValue { get; set; }

    public class ListItemModel
    {
        public int Value { get; set; }
        public string Text { get; set; }
        public string Title { get; set; }
    }
}

Properties

Name Type Description Notes Default Value
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 EmptyItemText String Text displayed when no value is selected.
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 ItemTextBinding IValueBinding<String> The expression of DataSource item that will be displayed in the control.
attribute
inner element
static value
bindable
default
null
property icon ItemTitleBinding IValueBinding The expression of DataSource item that will be placed into html title attribute.
attribute
inner element
static value
bindable
default
null
property icon ItemValueBinding IValueBinding The expression of DataSource item that will be passed to the SelectedValue property when the item is selected.
attribute
inner element
static value
bindable
default
null
property icon SelectedValue Object Gets or sets the value of the selected item.
attribute
inner element
static value
bindable
default
null
property icon SelectMenuSize Int32
attribute
inner element
static value
bindable
default
1
property icon Size Size Gets or sets the size of the ComboBox.
attribute
inner element
static value
bindable
default
Default

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