Dual list box in ASP.NET CORE ListBox Control

18 Oct 20223 minutes to read

The dual list box allows the user to move items between two list boxes by clicking the toolbar buttons. Dual list box can be created by listing items in the toolbarSettings along with the scope property.

The following operations can be performed in dual list box,

Options Description
moveUp Move the selected item in the upward direction within the list box.
moveDown Move the selected item in the downward direction within the list box.
moveTo Move the selected item to the another list box.
moveFrom Move the selected item from one list box to the another list box.
moveAllTo Move all the items to the another list box.
moveAllFrom Move all the items from one list box to the another list box.

The following example illustrates how to move items from Group A to Group B list box.

<div style="width:50%; margin:auto">
    <div style="float:left; width:48%">
        <ejs-listbox id="listbox1" dataSource="@ViewBag.groupA" scope="#listbox2">
            <e-listbox-toolbarSettings items="@ViewBag.items"></e-listbox-toolbarSettings>
        </ejs-listbox>
    </div>
    <div style="float:right; width:48%">
        <ejs-listbox id="listbox2" dataSource="@ViewBag.groupB"></ejs-listbox>
    </div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class ListBoxController : Controller
    {
        public IActionResult duallistbox()
        {
            ViewBag.groupA = new string[] { "Austrlia", "Bermuda", "Canada", "Cameroon", "Denmark", "France", "Finland", "Germany", "Hong kong" };
            ViewBag.groupB = new string[] { "India", "Italy", "Japan", "Mexico", "Norway", "Poland", "Switzerland", "United Kingdom", "United States" };
            ViewBag.items = new string[] { "moveUp", "moveDown", "moveTo", "moveFrom", "moveAllTo", "moveAllFrom" };
            return View();
        }
    }
}