Search results

Get the total count of data when remote data bind with DropDownList in ASP.NET MVC DropDownList control

03 Dec 2021 / 1 minute to read

Before control rendering, you can get the total items count by using actionComplete event with its result arguments. After rendering this control, you can get the total items count by using getItems method.

The following example demonstrate how to get the total items count.

Copied to clipboard
@Html.EJS().Button("btn").Content("Get Items").Render()
@Html.EJS().DropDownList("customers").Placeholder("Select a customer").PopupHeight("200px").DataSource(dataManger =>
            dataManger.Url("").Adaptor("ODataV4Adaptor").CrossDomain(true)).Fields(new DropDownListFieldSettings
                Text = "ContactName",
                Value = "CustomerID"
 function actionComplete (e) {
         // get total items count
         console.log("Total items count: " + e.result.length);
         var element = document.createElement('p');
         element.innerText = "Total items count: " + e.result.length;
    document.getElementById('btn').onclick = () => {
        var Obj = document.getElementById("customers").ej2_instances[0];
        // get items count using getItems method
        console.log("Total items count: " + Obj.getItems().length);
        let element = document.createElement('p');
        element.innerText = "Total items count: " + Obj.getItems().length;
Copied to clipboard
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 DropDownListController : Controller
        public ActionResult totalcount()
            return View();