Here I have created sample that will help you out.
Note : Dowload latest Bootstap-MultiSelect Plugin
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
rel="stylesheet" type="text/css" />
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function () {
GroupDropdownlist('ddlCategories')
$('[id*=ddlCategories]').multiselect({
enableCollapsibleOptGroups: true
});
});
function GroupDropdownlist(id) {
var selectControl = $('#' + id);
var groups = [];
$(selectControl).find('option').each(function () {
groups.push($(this).attr('data-group'));
});
var uniqueGroup = groups.filter(function (itm, i, a) {
return i == a.indexOf(itm);
});
$(uniqueGroup).each(function () {
var Group = jQuery('<optgroup/>', {
label: $(this)[0]
}).appendTo(selectControl);
var grpItems = $(selectControl).find('option[data-group="' + $(this)[0] + '"]');
$(grpItems).each(function () {
var item = $(this);
item.appendTo(Group);
});
});
}
</script>
</head>
<body>
<div>
<select name="ddlCategories" id="ddlCategories" multiple="multiple">
<option value="1" data-group="Science">BSC-IT</option>
<option value="2" data-group="Science">BSC-CS</option>
<option value="3" data-group="Science">BSC</option>
<option value="4" data-group="Commerce">BCOM-Marketing</option>
<option value="5" data-group="Commerce">BCOM-Finance</option>
<option value="6" data-group="Arts">BA</option>
<option value="7" data-group="Arts">MA</option>
</select>
</div>
</body>
</html>
Demo
Aspx
<div>
<%--Here Script Here used in HTML--%>
<asp:DropDownList ID="ddlCategories" runat="server" multiple="multiple">
</asp:DropDownList>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("SubCategoryId"), new DataColumn("SubCategoryName"), new DataColumn("CategoryName") });
dt.Rows.Add("1", "BSC-IT", "Science");
dt.Rows.Add("2", "BSC-CS", "Science");
dt.Rows.Add("3", "BSC", "Science");
dt.Rows.Add("4", "BCOM-Marketing", "Commerce");
dt.Rows.Add("5", "BCOM-Finance", "Commerce");
dt.Rows.Add("6", "BA", "Arts");
dt.Rows.Add("7", "MA", "Arts");
foreach (DataRow row in dt.Rows)
{
ListItem item = new ListItem();
item.Text = row["SubCategoryName"].ToString();
item.Value = row["SubCategoryId"].ToString();
item.Attributes["data-group"] = row["CategoryName"].ToString();
ddlCategories.Items.Add(item);
}
}
}
I hope this will help you out.