Search results

Dual listbox in ASP.NET MVC ListBox control

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.

razor
duallistbox.cs
<div style="width:50%; margin:auto">
    <div style="float:left; width:48%">
        @Html.EJS().ListBox("listbox1").DataSource((IEnumerable<object>)ViewBag.groupA).Scope("#listbox2").ToolbarSettings(new Syncfusion.EJ2.DropDowns.ListBoxToolbarSettings { Items = ViewBag.items }).Render()
    </div>
    <div style="float:right; width:48%">
        @Html.EJS().ListBox("listbox2").DataSource((IEnumerable<object>)ViewBag.groupB).Render()
    </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();
        }
    }
}