ASP.NET Core ListBox Overview

Telerik UI for ASP.NET Core Ninja image

The ListBox 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 ListBox TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers 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)
    )
    @addTagHelper *, Kendo.Mvc
    @{
        var tools = new string[] { "moveUp", "moveDown"};
    }

    <kendo-listbox name="optional" bind-to="ViewBag.Attendees">
        <toolbar position="ListBoxToolbarPosition.Right" tools="tools" />
    </kendo-listbox>

    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>())
    )

    @addTagHelper *, Kendo.Mvc

    @{
        var products = new List<ProductViewModel>();
        var products2 = new List<ProductViewModel>();
        var tools = new string[] { "moveUp", "moveDown", "transferTo", "transferFrom", "transferAllTo", "transferAllFrom", "remove" };
    }

    <kendo-listbox name="listbox1"
        datatextfield="ProductName"
        datavaluefield="ProductID"
        connect-with="listbox2"
        bind-to="products">
        <datasource>
            <transport>
                <read url="@Url.Action("GetProducts", "ListBox")"/>
            </transport>
        </datasource>
        <toolbar position="ListBoxToolbarPosition.Right" tools="tools"/>
    </kendo-listbox>

    <kendo-listbox name="listbox2"
        datatextfield="ProductName"
        datavaluefield="ProductID"
        connect-with="listbox1"
        bind-to="products2">
    </kendo-listbox>


    public IActionResult 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);
    }

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.

Next Steps

See Also

In this article