We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Multiples dropdownlist with check all

Hi,

In this article, you explain how set a check all in drop down list.

https://help.syncfusion.com/aspnetmvc/dropdownlist/howto

But I've a lot of drop down with this capabilities. I don't like define the same function for check or uncheck for each drop down.

The code
function create(args) {
            $("#check").ejCheckBox({ text: "Check All", change: "onallChange" });
        }
        function onallChange(args) {
            window.flag = true;
            var obj = $("#DropDownList1").ejDropDownList("instance");
            if (args.isChecked) obj.checkAll();
            else obj.uncheckAll();
            window.flag = false;
        }
How can I pass at function "onallChange" the drop down owner as parameter. Thus, this function can be generic.

Alternative solutions are welcome also

Thanks!

3 Replies

KV Karthikeyan Viswanathan Syncfusion Team January 2, 2017 08:41 AM UTC

Hi Manolo, 

 Thanks for Contacting Syncfusion Support. 

You can add generic check all option in dropdownlist by using below code snippet: 

<code> 
function create(args) { 
        $(".e-dropdownlist.check").ejCheckBox({ text: "Check All", change: "onallChange" }); 
    } 
    function onallChange(args) { 
        window.flag = true; 
        var obj = $("#" + this.element.parents(".e-ddl-popup").attr("id").replace("_popup_list_wrapper", "")).ejDropDownList("instance"); 
        if (args.isChecked) obj.checkAll(); 
        else obj.uncheckAll(); 
        window.flag = false; 
    } 
</code> 


Regards, 
Karthikeyan v. 



MA Manolo January 2, 2017 07:09 PM UTC

Hi,

Your code works perfectly, thanks, but I've other problem.

If I set all dropdowns in a form, if I set this definition in the controller

        [HttpPost]
        public JsonResult Filtrar(string ddlComunidad, string ddlProvincia, ddlSituacionMunicipio)
        {
            var datos = GetNNPP(ddlComunidad, ddlProvincia, ddlSituacionMunicipio)ToList();
            return Json(datos);
        }

I only get the first value cheked, not all values.




KV Karthikeyan Viswanathan Syncfusion Team January 3, 2017 04:19 AM UTC

Hi Manolo,  
 
 You can’t get the collection of selected items with in string argument otherwise you can get the items in list of string. You can get all checked items in dropdownlist by using below code snippet:  
 
<code>  
[HttpPost] 
        public JsonResult Filtrar(List<string> ddlComunidad, List<string> ddlProvincia) 
        { 
   
            return Json(ddlComunidad,JsonRequestBehavior.AllowGet); 
        } 
</code>  


 
Regards,  
Karthikeyan v.  


Loader.
Live Chat Icon For mobile
Up arrow icon