ComboBox HtmlHelper Overview
The Telerik UI ComboBox HtmlHelper for ASP.NET Core is a server-side wrapper for the Kendo UI ComboBox widget.
The ComboBox displays a list of values and allows for a single selection from the list.
The ComboBox is part of Telerik UI for ASP.NET Core, a
professional grade UI library with 100+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
Initializing the ComboBox
The following example demonstrates how to define the ComboBox by using the ComboBox HtmlHelper.
@(Html.Kendo().ComboBox()
.Name("combobox")
.DataTextField("ProductName")
.DataValueField("ProductID")
.DataSource(source => {
source.Read(read =>
{
read.Action("Products_Read", "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 HtmlHelper.
@(Html.Kendo().ComboBox()
.Name("combobox")
.DataTextField("ProductName")
.DataValueField("ProductID")
.HtmlAttributes(new { style = "width:100%" })
.Filter("contains")
.MinLength(3)
.Height(290)
.HeaderTemplate(
"<div class=\"dropdown-header k-widget k-header\">" +
"<span>Products</span>" +
"</div>")
.FooterTemplate("Total <strong>#: instance.dataSource.total() #</strong> items found")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Products_Read2", "DropDownList");
})
.ServerFiltering(false);
})
.Events(e => e
.Change("onChange")
.Select("onSelect")
.Open("onOpen")
.Close("onClose")
.DataBound("onDataBound")
.Filtering("onFiltering")
)
)
<script type="text/javascript">
$(function () {
// The Name() of the ComboBox is used to get its client-side instance.
var combobox = $("#combobox").data("kendoComboBox");
console.log(combobox);
});
</script>
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")
)
)
<script>
function combobox_select() {
// Handle the select event.
}
function combobox_change() {
// Handle the change event.
}
</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>)
)
)