Click here to Skip to main content
13,398,920 members (34,292 online)
Click here to Skip to main content
Add your own
alternative version


168 bookmarked
Posted 25 Sep 2008

Multiselect Dropdown for Web Applications

, 17 Dec 2008
Rate this:
Please Sign up or sign in to vote.
How to select multiple values from 'a dropdown look & feel' in a Web application


Whenever there is a requirement of selecting multiple values in a Web application, where space holds an importance and one needs a client-interactive User Interface – a control that has an auto-collapse feature and looks like multiple select dropdown is a good fit.

This is a control that allows a user to select multiple values through a dropdown. It clubs input element, an image and a checkboxlist to give a feel of multi-selectable dropdown. It has an auto-collapse feature apart from explicit close option giving it a total feel of a normal dropdown. The control can be tweaked by developers as per their own needs very easily. The code sample of the same is attached with the article.


We needed to provide an option of multi-select in our project lately. For multiple select, ASP.NET provides CheckBoxList which takes quite a lot of space and does not always fit in the UI requirements. In our UI and as per the customer's request, we were asked to use a dropdown like feature that can select multiple values (just like one of the controls in .NET Windows). I searched on The Code Project and Googled it but could hardly find any control that gave a dropdown look and allowed multiple select. Some were there but they weren't free! So, I went ahead and made my own. And since I was making it myself, I added all the features that I thought would be user friendly.

Using the Code

The first thing was to place the controls to give the look and feel of a dropdown. This was achieved in HTML using proper CSS for the controls.

<div id="divCustomCheckBoxList" runat="server" onmouseover="clearTimeout(timoutID);"

         onmouseout="timoutID = setTimeout('HideMList()', 750);">
            <td align="right" class="DropDownLook">
               <input id="txtSelectedMLValues" type="text" readonly="readonly"

                 onclick="ShowMList()" style="width:229px;" runat="server" />
            <td align="left" class="DropDownLook">
               <img id="imgShowHide" runat="server" src="drop.gif"

                          onclick="ShowMList()" align="left" />
            <td colspan="2" class="DropDownLook">
                   <div runat="server" id="divCheckBoxListClose" class="DivClose">
                         <label runat="server" onclick="HideMList();"

                                   class="LabelClose" id="lblClose"> x</label>
                   <div runat="server" id="divCheckBoxList" class="DivCheckBoxList">
                         <asp:CheckBoxList ID="lstMultipleValues" runat="server"

                          Width="250px" CssClass="CheckBoxList"></asp:CheckBoxList>

CSS has a very important part out here to give it a dropdown look:





While the CheckBoxList control was populated, a JavaScript handler was attached to it such that selection/de-selection of any option reflects in the input element (in selected values placed in a dropdown).

// Append an event to the checkboxes in the list
lstMultipleValues.Attributes.Add("onclick", "FindSelectedItems
         (this," + txtSelectedMLValues.ClientID + ");");

Using JavaScript, we keep track of what is selected in the list. Further, the open and close of the div-elements are also handled through JavaScipts using onMouseOver, onMouseOut events.

<script type="text/javascript">
   var timoutID;

   //This function shows the checkboxlist
   function ShowMList()
       var divRef = document.getElementById("divCheckBoxList"); = "block";
       var divRefC = document.getElementById("divCheckBoxListClose"); = "block";

   //This function hides the checkboxlist
   function HideMList()
       document.getElementById("divCheckBoxList").style.display = "none";
       document.getElementById("divCheckBoxListClose").style.display = "none";

   //This function finds the checkboxes selected in the list and using them,
   //it shows the selected items text in the textbox (comma separated)
   function FindSelectedItems(sender,textBoxID)
       var cblstTable = document.getElementById(;
       var checkBoxPrefix = + "_";
       var noOfOptions = cblstTable.rows.length;
       var selectedText = "";
       for(i=0; i < noOfOptions ; ++i)
             if(selectedText == "")
                selectedText = document.getElementById
                selectedText = selectedText + "," +
       document.getElementById( = selectedText;

The client side events of controls are used in a way such that as long as we have a mouse over the control (textbox or dropdown or checkboxlist or scroll) the list is open. Once the mouse leaves the control, after a certain time (configurable), it gets collapsed automatically. To add more flexibility for the user, a close option is also provided at the bottom of the control. Developers can tweak the control as per their requirements.

Points of Interest

The work was appreciated by the team members and the client finds it to be a good, clean way to provide users with a multi-select option! Last but not the least, it is free!


  • 14th December, 2008: Wordings changed
  • 25th September, 2008: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sandeep Mewara
Software Developer (Senior)
India India
Current location: Bangalore, India.

You may also be interested in...


Comments and Discussions

AnswerRe: Thanks Nice Pin
Sandeep Mewara20-Oct-08 21:20
memberSandeep Mewara20-Oct-08 21:20 
AnswerRe: Thanks Nice Pin
Sandeep Mewara20-Oct-08 22:33
memberSandeep Mewara20-Oct-08 22:33 
GeneralA couple of things!! Pin
m_irfan14-Oct-08 12:03
memberm_irfan14-Oct-08 12:03 
AnswerRe: A couple of things!! Pin
Sandeep Mewara15-Oct-08 3:49
memberSandeep Mewara15-Oct-08 3:49 
GeneralBUG: No scroll bar showed up Pin
BYQL1-Oct-08 14:34
memberBYQL1-Oct-08 14:34 
AnswerRe: BUG: No scroll bar showed up Pin
Sandeep Mewara3-Oct-08 5:19
memberSandeep Mewara3-Oct-08 5:19 
AnswerRe: BUG: No scroll bar showed up Pin
Sandeep Mewara20-Oct-08 21:33
memberSandeep Mewara20-Oct-08 21:33 
GeneralError when loading the solution MultiSelectDropDownEx.sln Pin
Jean Doiron1-Oct-08 12:02
memberJean Doiron1-Oct-08 12:02 
When I try to open the solution, I get the following error message;

The application for project 'C:\...\MultiSelectDropDownEx' is not

Make sure the application for the project type () is installed.

I have Visual Studio 2005 and Visual Studio 2008.
I also have installed Ms VB 2008, Ms C# 2008 and Ms C++ 2008.

What could I be missing?
AnswerRe: Error when loading the solution MultiSelectDropDownEx.sln Pin
Sandeep Mewara1-Oct-08 22:16
memberSandeep Mewara1-Oct-08 22:16 
GeneralRe: Error when loading the solution MultiSelectDropDownEx.sln Pin
Jean Doiron2-Oct-08 5:57
memberJean Doiron2-Oct-08 5:57 
AnswerRe: Error when loading the solution MultiSelectDropDownEx.sln Pin
Sandeep Mewara2-Oct-08 9:17
memberSandeep Mewara2-Oct-08 9:17 
GeneralRoll into custom control Pin
MCofer29-Sep-08 9:43
memberMCofer29-Sep-08 9:43 
AnswerRe: Roll into custom control Pin
Sandeep Mewara29-Sep-08 10:09
memberSandeep Mewara29-Sep-08 10:09 
GeneralRe: Roll into custom control Pin
Member 152693030-Sep-08 7:59
memberMember 152693030-Sep-08 7:59 
GeneralRe: Roll into custom control Pin
gregg.drennan@pb.com2-Oct-08 7:43
membergregg.drennan@pb.com2-Oct-08 7:43 
GeneralRe: Roll into custom control Pin
bobby Builder17-Oct-08 7:01
memberbobby Builder17-Oct-08 7:01 
GeneralRe: Roll into custom control Pin
fhoon8210-Jan-10 23:26
memberfhoon8210-Jan-10 23:26 
AnswerRe: Roll into custom control Pin
Sandeep Mewara12-Jan-10 19:31
memberSandeep Mewara12-Jan-10 19:31 
GeneralNice Pin
Abhijit Jana25-Sep-08 19:20
memberAbhijit Jana25-Sep-08 19:20 
AnswerRe: Nice Pin
Sandeep Mewara25-Sep-08 20:18
memberSandeep Mewara25-Sep-08 20:18 
GeneralCool Idea Pin
inetfly12325-Sep-08 7:31
memberinetfly12325-Sep-08 7:31 
AnswerRe: Cool Idea Pin
Sandeep Mewara25-Sep-08 20:18
memberSandeep Mewara25-Sep-08 20:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180218.2 | Last Updated 17 Dec 2008
Article Copyright 2008 by Sandeep Mewara
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid