Introduction

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.

Background

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.

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).

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!

Great project and just what I was looking for! And many thanks to the person who added the master page JS!!

I created a version in .NET 4.5 that I will upload to GIT as a forked project when I have time. Can I just upload the project as part of this article and make it a fork? New to GIT and haven't mastered it yet. (Or is it too obvious and not worth the effort?!)

Steps to update to .NET 4.5 and VS2012:

I changed the version in the "Configuration Manager" to .NET 4.5
I used NuGet to Install "AJAX Control Toolkit".
I added a master page and added the link to the CSS & the JavaScript (added by another user ~ thanks!) to the master page.
I added a new .aspx page and linked it to the master page and copied all the script from Default.aspx to my new page (I did the same with the Default.aspx.cs).

Thank you so much for this code. i have been trying all kinds of sample mulitselectdropdown from internet without success. with yours code, when i run it, it just works. Thank you thank you so much for sharing this!!!!

i've been trying for hours.but i couldn't.i think that problem is here.
lstMultipleValues.Attributes.Add("onclick", "FindSelectedItems(this," + txtSelectedMLValues.ClientID + ");");
it is not working only FF.can you help me_?