Example of Dual ListBox in ASP.NET MVC ListBox Control
This sample demonstrates the functionalities of the dual list box. Select an item from Group A and click the moveTo button to move item from Group A to Group B.
NO DATA AVAILABLE
Group A
- Australia
- Bermuda
- Canada
- Cameroon
- Denmark
- France
- Finland
- Germany
- Hong Kong
Group B
- India
- Italy
- Japan
- Mexico
- Norway
- Poland
- Switzerland
- United Kingdom
- United States
@Html.UiListBox("listbox1", new UiListBoxOptions
{
Scope = "listbox2",
Height = "330px",
Toolbar = new List<UiListBoxTool> { UiListBoxTool.MoveUp, UiListBoxTool.MoveDown, UiListBoxTool.MoveTo, UiListBoxTool.MoveFrom, UiListBoxTool.MoveAllTo, UiListBoxTool.MoveAllFrom },
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DataSource = (IEnumerable<object>)ViewData["groupA"],
NoRecordsTemplate = "#noData"
})
@Html.UiListBox("listbox2", new UiListBoxOptions
{
Scope = "listbox1",
Height = "330px",
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DataSource = (IEnumerable<object>)ViewData["groupB"],
NoRecordsTemplate = "#noData"
})
<style>
.dual-list-wrapper { display: flex; justify-content: center; gap: 24px; padding-top: 30px; }
.dual-list-box { width: 300px; }
.e-list-nrt { text-align: center; padding: 24px 0; opacity: .6; }
</style>
<template id="noData"><div class="e-list-nrt"><span>NO DATA AVAILABLE</span></div></template>
<div class="control-section">
<div class="dual-list-wrapper">
<div class="dual-list-box">
<h4>Group A</h4>
@Html.UiListBox("listbox1", new UiListBoxOptions
{
Scope = "listbox2",
Height = "330px",
Toolbar = new List<UiListBoxTool> { UiListBoxTool.MoveUp, UiListBoxTool.MoveDown, UiListBoxTool.MoveTo, UiListBoxTool.MoveFrom, UiListBoxTool.MoveAllTo, UiListBoxTool.MoveAllFrom },
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DataSource = (IEnumerable<object>)ViewData["groupA"],
NoRecordsTemplate = "#noData"
})
</div>
<div class="dual-list-box">
<h4>Group B</h4>
@Html.UiListBox("listbox2", new UiListBoxOptions
{
Scope = "listbox1",
Height = "330px",
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DataSource = (IEnumerable<object>)ViewData["groupB"],
NoRecordsTemplate = "#noData"
})
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ListBoxController : Controller
{
// The page is Views/ListBox/DualListBox.cshtml; it draws what ViewData holds.
public ActionResult DualListBox()
{
List<object> groupA = new List<object>();
groupA.Add(new { Name = "Australia", Code = "AU" });
groupA.Add(new { Name = "Bermuda", Code = "BM" });
groupA.Add(new { Name = "Canada", Code = "CA" });
groupA.Add(new { Name = "Cameroon", Code = "CM" });
groupA.Add(new { Name = "Denmark", Code = "DK" });
groupA.Add(new { Name = "France", Code = "FR" });
groupA.Add(new { Name = "Finland", Code = "FI" });
groupA.Add(new { Name = "Germany", Code = "DE" });
groupA.Add(new { Name = "Hong Kong", Code = "HK" });
ViewData["groupA"] = groupA;
List<object> groupB = new List<object>();
groupB.Add(new { Name = "India", Code = "IN" });
groupB.Add(new { Name = "Italy", Code = "IT" });
groupB.Add(new { Name = "Japan", Code = "JP" });
groupB.Add(new { Name = "Mexico", Code = "MX" });
groupB.Add(new { Name = "Norway", Code = "NO" });
groupB.Add(new { Name = "Poland", Code = "PL" });
groupB.Add(new { Name = "Switzerland", Code = "CH" });
groupB.Add(new { Name = "United Kingdom", Code = "GB" });
groupB.Add(new { Name = "United States", Code = "US" });
ViewData["groupB"] = groupB;
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The dual list box allows the user to move items between two list boxes. Dual list box can be created by listing items in the ToolbarSettings property along with Scope property. The supported operations are,
moveUp- Moves the selected item in the upward direction.moveDown- Moves the selected item in the downward direction.moveTo- Moves the selected item to the Group B list box.moveFrom- Moves the selected item from Group B list box to Group A.moveAllTo- Moves all the items to the Group B list box.moveAllFrom- Moves all the items from Group B list box to Group A.