Introduction
In this blog, I am going to explain MultiSelect DropDownList with CheckBoxes in ASP.Net with C# and VB.NET using jQuery Plugin.
Recently, a few days ago, one of my classmates tried to implement MultiSelect DropDownList with CheckBoxes in ASP.Net but unfortunately, we couldn't find a better solution for that. He said there is one MultiSelect DropDownList with CheckBoxes but when he selects the checkbox, the checked value is not displayed in the drop-down list. Now, what he should do?
In this blog, I'll explain in brief how to create a multi-select DropDown list with CheckBoxes in ASP.NET with C# and VB.NET using jQuery Plugin.
So, let's take one example for demonstration.
For that, you need to download jQuery Bootstrap Multi-Select Plugin.
You can get the reference from the given link.

http://davidstutz.de/bootstrap-multiselect/

ASP.NET (HTML CODE)
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>MultiSelect DropDownList with CheckBoxes in ASP.Net</title>
  6. </head>
  7. <body>
  8. <form id="form1" runat="server">
  9. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  10. <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
  11. rel="stylesheet" type="text/css" />
  12. <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
  13. <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
  14. rel="stylesheet" type="text/css" />
  15. <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
  16. type="text/javascript"></script>
  17. <script type="text/javascript">
  18. $(function () {
  19. $('[id*=lstEmployee]').multiselect({
  20. includeSelectAllOption: true
  21. });
  22. });
  23. </script>
  24. Employee : <asp:ListBox ID="lstEmployee" runat="server" SelectionMode="Multiple">
  25. <asp:ListItem Text="Nikunj Satasiya" Value="1" />
  26. <asp:ListItem Text="Dev Karathiya" Value="2" />
  27. <asp:ListItem Text="Hiren Dobariya" Value="3" />
  28. <asp:ListItem Text="Vivek Ghadiya" Value="4" />
  29. <asp:ListItem Text="Pratik Pansuriya" Value="5" />
  30. </asp:ListBox>
  31. <asp:Button Text="Submit" runat="server" OnClick="Submit" />
  32. </form>
  33. </body>
  34. </html>
Script
  1. <script type="text/javascript">
  2. $(function () {
  3. $('[id*=lstEmployee]').multiselect({
  4. includeSelectAllOption: true
  5. });
  6. });
  7. </script>
C# Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. public partial class CS : System.Web.UI.Page
  8. {
  9. protected void Submit(object sender, EventArgs e)
  10. {
  11. string message = "";
  12. foreach (ListItem item in lstEmployee.Items)
  13. {
  14. if (item.Selected)
  15. {
  16. message += item.Text + " " + item.Value + "\\n";
  17. }
  18. }
  19. ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);
  20. }
  21. }
VB.NET Code
  1. Partial Class VB
  2. Inherits System.Web.UI.Page
  3. Protected Sub Submit(sender As Object, e As EventArgs)
  4. Dim message As String = ""
  5. For Each item As ListItem In lstEmployee.Items
  6. If item.Selected Then
  7. message += item.Text + " " + item.Value + "\n"
  8. End If
  9. Next
  10. ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", "alert('" & message & "');", True)
  11. End Sub
  12. End Class
Output
Summary
Using Query Bootstrap Multi-Select Plugin, you can easily create MultiSelect DropDownList with checkboxes in ASP.NET.