In this article, I will explain how to implement a Multiple Select (MultiSelect) DropDownList with CheckBoxes in ASP.NET with jQuery Bootstrap Multi-Select Plugin.

To actualize a Multiple Select (MultiSelect) DropDownList with CheckBoxes in ASP.NET, we should make use of ListBox control and apply jQuery Bootstrap Multi-Select Plugin to it.
If you are a beginner in ASP.NET MVC and jQuery, I am listing some important links to learn-
You can follow the simple steps, given below, to implement a Multiple Select DropdownList with CheckBox. I am creating a MVC Application and creating controller "Home".

In the next step, create an Action to open the view "Index". See the example, given below-
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace DropdownCheckbox.Controllers
  7. {
  8. public class HomeController : Controller
  9. {
  10. public ActionResult Index()
  11. {
  12. return View();
  13. }
  14. }
  15. }
Create view name as "Index.cshtml". See the example, given below-
  1. @{
  2. ViewBag.Title = "Home Page";
  3. Layout = null;
  4. }
  5. <div>
  6. <table>
  7. <tr>
  8. <td><p >Select Expert's Name </p></td>
  9. <td>
  10. <select id="EmpList" multiple="multiple">
  11. <option value="1">Navdeep-Asp.net</option>
  12. <option value="2">Pankaj-C#</option>
  13. <option value="3">Bikesh-Asp.Net</option>
  14. <option value="4">Pritam-Salesforce</option>
  15. <option value="5">Payal-Salesforce</option>
  16. <option value="6">Sujata-SSRS</option>
  17. <option value="7">Harikant-UI</option>
  18. </select>
  19. </td>
  20. <td><input type="button" id="btnSelected" value="Get Selected" /></td>
  21. </tr>
  22. </table>
  23. </div>
In this article, I am using hard code value, but you can bind from the database. Afterwards, add jQuery Plugins or CDN, as shown below-
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  2. <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
  3. rel="stylesheet" type="text/css" />
  4. <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
  5. <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
  6. rel="stylesheet" type="text/css" />
  7. <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
  8. type="text/javascript"></script>
Use the references in your Application.

Afterwards, write JS code to implement multiselect with Checkbox in Dropdown. Use the code, given below-
  1. <script type="text/javascript">
  2. $(function () {
  3. $('#EmpList').multiselect({
  4. includeSelectAllOption: true
  5. });
  6. $('#btnSelected').click(function () {
  7. var selected = $("#EmpList option:selected");
  8. var message = "";
  9. selected.each(function () {
  10. message += $(this).text() + " " + $(this).val() + "\n";
  11. });
  12. alert(message);
  13. });
  14. });
  15. </script>
Set routing inside "route.config" file. See the code, given below-
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Routing;
  7. namespace DropdownCheckbox
  8. {
  9. public class RouteConfig
  10. {
  11. public static void RegisterRoutes(RouteCollection routes)
  12. {
  13. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  14. routes.MapRoute(
  15. name: "Default",
  16. url: "{controller}/{action}/{id}",
  17. defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  18. );
  19. }
  20. }
  21. }

Complete code

You can see and understand the complete code, given below-
  1. @{
  2. ViewBag.Title = "Home Page";
  3. Layout = null;
  4. }
  5. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  6. <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
  7. rel="stylesheet" type="text/css" />
  8. <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
  9. <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
  10. rel="stylesheet" type="text/css" />
  11. <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
  12. type="text/javascript"></script>
  13. <script type="text/javascript">
  14. $(function () {
  15. $('#EmpList').multiselect({
  16. includeSelectAllOption: true
  17. });
  18. $('#btnSelected').click(function () {
  19. var selected = $("#EmpList option:selected");
  20. var message = "";
  21. selected.each(function () {
  22. message += $(this).text() + " " + $(this).val() + "\n";
  23. });
  24. alert(message);
  25. });
  26. });
  27. </script>
  28. <div>
  29. <table>
  30. <tr>
  31. <td><p >Select Expert's Name </p></td>
  32. <td>
  33. <select id="EmpList" multiple="multiple">
  34. <option value="1">Navdeep-Asp.net</option>
  35. <option value="2">Pankaj-C#</option>
  36. <option value="3">Bikesh-Asp.Net</option>
  37. <option value="4">Pritam-Salesforce</option>
  38. <option value="5">Payal-Salesforce</option>
  39. <option value="6">Sujata-SSRS</option>
  40. <option value="7">Harikant-UI</option>
  41. </select>
  42. </td>
  43. <td><input type="button" id="btnSelected" value="Get Selected" /></td>
  44. </tr>
  45. </table>
  46. </div>
Now, run the Application and see the output, as shown below-


According to the example, I can select any one or multiple choices. Also, you can see the count of the selected items.

We can see the item on the popup after clicking on "
GetSelected".
I hope, you enjoyed this article and learned lots of things. If you have any confusion regarding these topics, you can download the project.