ComboBox Overview

Telerik UI for ASP.NET Core Ninja image

The ComboBox is part of Telerik UI for ASP.NET Core, a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

The Telerik UI ComboBox TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI ComboBox widget.

The ComboBox displays a list of values and allows for a single selection from the list.

Initializing the ComboBox

The following example demonstrates how to define the ComboBox.

    @(Html.Kendo().ComboBox()
        .Name("combobox")
        .DataTextField("ProductName")
        .DataValueField("ProductID")
        .DataSource(source => {
            source.Read(read =>
            {
                read.Action("Products_Read", "ComboBox");
            });
        })
    )
    <kendo-combobox name="combobox"
                datatextfield="ProductName"
                datavaluefield="ProductID">
    <datasource>
        <transport>
            <read url="@Url.Action("Products_Read", "ComboBox")"/>
        </transport>
    </datasource>
</kendo-combobox>

    public class ComboBoxController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public JsonResult Products_Read()
        {
            var result = Enumerable.Range(0, 50).Select(i => new ProductViewModel
            {
                ProductID = "" + i,
                ProductName = "Product " + i
            });

            return Json(result);
        }
    }

Basic Configuration

The following example demonstrates the basic configuration of the ComboBox.

    @(Html.Kendo().ComboBox()
          .Name("products")
          .Placeholder("Select product")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:100%;" })
          .Filter(FilterType.Contains)
          .AutoBind(false)
          .MinLength(3)
          .DataSource(source => source
              .Read(read => read.Action("GetProducts", "Home"))
          )
    )
    @addTagHelper *, <<Your Project Name Goes Here>>

    <kendo-combobox name="products" filter="FilterType.Contains"
                        placeholder="Select product"
                        datatextfield="ProductName"
                        datavaluefield="ProductID"
                        auto-bind="false"
                        min-length="3" style="width: 100%;">
        <datasource type="DataSourceTagHelperType.Custom">
            <transport>
                <read url="@Url.Action("GetProducts", "Home")" />
            </transport>
        </datasource>
    </kendo-combobox>
    public JsonResult GetProducts()
    {
        return new JsonResult(new[] { new { ProductName = "ProductName 1", ProductID = 1} });
    }

Functionality and Features

Events

You can subscribe to all ComboBox events. For a complete example on basic ComboBox events, refer to the demo on using the events of the ComboBox.

Handling by Handler Name

The following example demonstrates how to subscribe to events by a handler name.

    @(Html.Kendo().ComboBox()
        .Name("combobox")
        .BindTo(new string[] { "Item1", "Item2", "Item3" })
        .Events(e => e
            .Select("combobox_select")
            .Change("combobox_change")
        )
    )
@{ 
    var items = new string[] { "Item 1", "Item 2", "Item 3" };
}
<kendo-combobox name="combobox"
                bind-to="items"
                on-select="combobox_select"
                on-change="combobox_change">
</kendo-combobox>
    <script>
    function combobox_select() {
        // Handle the select event.
    }

    function combobox_change() {
        // Handle the change event.
    }

    $(document).ready(function() {
        var comboBoxWidget = $("#combobox").data("kendoComboBox"); //Get an instance of the ComboBox.
        comboBoxWidget.value("Item3"); //Set the value of the ComboBox programmatically when the page has finished loading.
        comboBoxWidget.trigger("change"); //Trigger the "change" event manually (the value() method does not trigger it). Refer to the client-side API for further details.
    });
    </script>

Handling by Template Delegate

The following example demonstrates how to subscribe to events by a template delegate.

    @(Html.Kendo().ComboBox()
        .Name("combobox")
        .BindTo(new string[] { "Item1", "Item2", "Item3" })
        .Events(e => e
            .Select(@<text>
            function() {
                // Handle the select event inline.
            }
            </text>)
            .Change(@<text>
            function() {
                // Handle the change event inline.
            }
            </text>)
        )
    )

See Also

In this article