Select2ComboBox

in namespace DotVVM.Bootstrap5.Select2.Controls

Usage & Scenarios

Extends the Bootstrap 5 ComboBox control with the Select2 widget, which provides search and improved keyboard navigation.

Install the DotVVM.Controls.Bootstrap5.Select2 package and register it in DotvvmStartup.cs after Bootstrap 5:

config.AddBootstrap5Configuration();
config.AddBootstrap5Select2Configuration();

The control uses the bs prefix and supports all properties of ComboBox.

Sample 1: Searchable Combo Box

Select2ComboBox accepts the same data-binding properties as ComboBox. The Select2 widget lets users search the available items.

<bs:Select2ComboBox SelectedValue="{value: SelectedCountry}"
                    DataSource="{value: Countries}"
                    ItemTextBinding="{value: Name}"
                    ItemValueBinding="{value: Code}" />

<p>Selected country: <strong>{{value: SelectedCountry}}</strong></p>
using DotVVM.Framework.ViewModel;
using System.Collections.Generic;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap5_select2.Select2ComboBox.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public List<Country> Countries { get; set; } = new List<Country>
        {
            new Country { Code = "CZ", Name = "Czech Republic" },
            new Country { Code = "DE", Name = "Germany" },
            new Country { Code = "PL", Name = "Poland" },
            new Country { Code = "SK", Name = "Slovakia" }
        };

        public string SelectedCountry { get; set; }

        public class Country
        {
            public string Code { get; set; }
            public string Name { 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 Gets or sets the number of visible options in the select menu. If set to 1, the select menu will be rendered as a dropdown.
attribute
inner element
static value
bindable
default
1
property icon Size 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