Example of Multiple Selection in ASP.NET MVC DropDownTree Control
This sample explains you about the multiple item selection functionalities of the Dropdown Tree. To select multiple items, you may press and hold the CTRL key and then select the desired items; or select any item by selecting it and then press and hold the SHIFT key to select a range of items continuously.
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select items",
AllowMultiSelection = true,
PopupHeight = "200px",
DataSource = (IEnumerable<object>)ViewData["data"],
Fields = new UiDropDownFields { Value = "id", Text = "name", ParentValue = "pid", Expanded = "expanded" }
})
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
</style>
<div class="control-section">
<div class="content" style="padding-top:75px">
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select items",
AllowMultiSelection = true,
PopupHeight = "200px",
DataSource = (IEnumerable<object>)ViewData["data"],
Fields = new UiDropDownFields { Value = "id", Text = "name", ParentValue = "pid", Expanded = "expanded" }
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DropDownTreeController : Controller
{
// The page is Views/DropDownTree/MultipleSelection.cshtml; it draws what ViewData holds.
public ActionResult MultipleSelection()
{
ViewData["data"] = new DropDownTreeMultiSelection().MultipleSelection();
return View();
}
public class DropDownTreeMultiSelection
{
public List<Object> MultipleSelection()
{
List<object> parentitem = new List<object>();
parentitem.Add(new { id = 1, name = "Australia", hasChild = true, expanded = true });
parentitem.Add(new { id = 2, pid = 1, name = "New South Wales" });
parentitem.Add(new { id = 3, pid = 1, name = "Victoria" });
parentitem.Add(new { id = 4, pid = 1, name = "South Australia" });
parentitem.Add(new { id = 6, pid = 1, name = "Western Australia" });
parentitem.Add(new { id = 7, name = "Brazil", hasChild = true });
parentitem.Add(new { id = 8, pid = 7, name = "Paraná" });
parentitem.Add(new { id = 9, pid = 7, name = "Ceará" });
parentitem.Add(new { id = 10, pid = 7, name = "Acre" });
parentitem.Add(new { id = 11, name = "China", hasChild = true });
parentitem.Add(new { id = 12, pid = 11, name = "Guangzhou" });
parentitem.Add(new { id = 13, pid = 11, name = "Shanghai" });
parentitem.Add(new { id = 14, pid = 11, name = "Beijing" });
parentitem.Add(new { id = 15, pid = 11, name = "Shantou" });
parentitem.Add(new { id = 16, name = "France", hasChild = true });
parentitem.Add(new { id = 17, pid = 16, name = "Pays de la Loire" });
parentitem.Add(new { id = 18, pid = 16, name = "Aquitaine" });
parentitem.Add(new { id = 19, pid = 16, name = "Brittany" });
parentitem.Add(new { id = 20, pid = 16, name = "Lorraine" });
parentitem.Add(new { id = 21, name = "India", hasChild = true });
parentitem.Add(new { id = 22, pid = 21, name = "Assam" });
parentitem.Add(new { id = 23, pid = 21, name = "Bihar" });
parentitem.Add(new { id = 24, pid = 21, name = "Tamil Nadu" });
parentitem.Add(new { id = 25, pid = 21, name = "Punjab" });
return parentitem;
}
}
}
}
@* 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 Dropdown Tree control allows you to select multiple items by enabling the AllowMultiSelection property.
In this demo, the Dropdown Tree is enabled with multiple selection.