ASP.NET MVC ListBox Overview
The ListBox is part of Telerik UI for ASP.NET MVC, 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 ListBox HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI ListBox widget.
The ListBox displays a list of data inside a box and allows single or multiple selections, reordering of selected items, deleting items, fast keyboard-only navigation through the component items, as well as dragging and dropping items. You can also connect the ListBox to other ListBoxes and customize its items with templates, toolbar positioning, placeholders, hints, and localization of its command buttons' messages.
Initializing the ListBox
The following example demonstrates how to define the ListBox.
@(Html.Kendo().ListBox()
.Name("optional")
.Toolbar(toolbar =>
{
toolbar.Position(Kendo.Mvc.UI.Fluent.ListBoxToolbarPosition.Right);
toolbar.Tools(tools => tools
.MoveUp()
.MoveDown()
);
})
.BindTo(ViewBag.Attendees)
)
public ActionResult Index()
{
ViewBag.Attendees = new List<string>
{
"Steven White",
"Nancy King",
"Nancy Davolio",
"Robert Davolio",
"Michael Leverling",
"Andrew Callahan",
"Michael Suyama"
};
return View();
}
Basic Configuration
The following example demonstrates the basic configuration of two connected ListBox components.
@(Html.Kendo().ListBox()
.Name("listbox1")
.DataValueField("ProductID")
.DataTextField("ProductName")
.DataSource(source => source
.Read(read => read.Action("GetProducts", "ListBox"))
)
.ConnectWith("listbox2")
.Toolbar(toolbar =>
{
toolbar.Position(ListBoxToolbarPosition.Right);
toolbar.Tools(tools => tools
.MoveUp()
.MoveDown()
.TransferTo()
.TransferFrom()
.TransferAllTo()
.TransferAllFrom()
.Remove());
})
.BindTo(new List<ProductViewModel>())
)
@(Html.Kendo().ListBox()
.Name("listbox2")
.DataValueField("ProductID")
.DataTextField("ProductName")
.ConnectWith("listbox1")
.BindTo(new List<ProductViewModel>())
)
public ActionResult GetProducts()
{
var products = Enumerable.Empty<ProductViewModel>();
using (var northwind = GetContext())
{
products = northwind.Products.Select(product => new ProductViewModel
{
ProductID = product.ProductID,
ProductName = product.ProductName
}).ToList();
}
return Json(products, JsonRequestBehavior.AllowGet);
}
Functionality and Features
Feature | Description |
---|---|
Data Binding | The ListBox can bind to local data collections or remote data. |
Item templates | You can use the component template option to customize the rendering of its items. |
Dragging and dropping | Enable the drag-and-drop feature of the ListBox items. |
Selection | The component supports single and multiple selection modes. |
Events | The ListBox emits various events that you can handle and use to control what happens during the user interaction. |
Globalization | The ListBox provides globalization through the combination of localization and right-to-left support. |
Accessibility | The ListBox is accessible for screen readers, supports WAI-ARIA attributes, and delivers keyboard shortcuts for faster navigation. |