Enable or disable items

17 Feb 20222 minutes to read

To enable or disable items in the list box, enableItems method can be used. In the following example, the Bugatti Veyron Super Sport and SSC Ultimate Aero items are disabled by default and by clicking Enable Items buttons, the disabled items will be enabled.

<ejs-listbox id="listbox" dataSource="@ViewBag.data" created="create"></ejs-listbox>
<button id="enableitem" class="e-btn">Enable Items</button>

<script>
    var disableItems = ['Bugatti Veyron Super Sport', 'SSC Ultimate Aero'];
    function create() {
        listboxobj = ej.base.getInstance(document.getElementById('listbox'), ejs.dropdowns.ListBox);
        listboxobj.enableItems(disableItems, false);
    }

    document.getElementById('enableitem').onclick = function(){
        listboxobj = ej.base.getInstance(document.getElementById('listbox'), ejs.dropdowns.ListBox);
        listboxobj.enableItems(disableItems, true);
    }
</script>
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 enableitem()
        {
            ViewBag.data = new string[] { "BadmHennessey Venominton", "Bugatti Veyron Super Sport", "SSC Ultimate Aero", "Bugatti Chiron", "Koenigsegg CCR", "McLaren F1", "Aston Martin One- 77", "Jaguar XJ220" };
            return View();
        }
    }
}