Click here to Skip to main content
13,401,500 members (50,965 online)
Click here to Skip to main content
Add your own
alternative version


49 bookmarked
Posted 6 May 2009

DropDown and MultiselectDropDown Controls for ASP.NET

, 6 May 2009
Rate this:
Please Sign up or sign in to vote.
Custom DropDown and MultiselectDropDown controls with data binding support


This article discusses about two user controls written in ASP.NET. Working on a project recently, I needed to develop a custom DropDown control with multiselect options in the form of CheckBox. I searched around for something simple, yet useful for my needs, and I wasn't able to find anything, so I developed my own control. Later, I reused the code to create a regular DropDown control (no multiselect checkbox options). The two controls can be merged into one, but I might do that at a later stage. On to the controls. 


This control can be bound to a IListSource to fetch data to be populated, in addition to the regular Items collection that can be populated from the asp. Here are a few examples of how this control can be used in ASPX.

<%@ Register Src="Controls/DropDown.ascx" TagName="DropDown" TagPrefix="thp" %>

<thp:DropDown ID="DropDown1" runat="server" Width="200">
          <asp:ListItem Text="Some text" Value="0" Selected="True" />
          <asp:ListItem Text="Another option" Value="1" />
<thp:DropDown ID="DropDown2" runat="server" Width="200" DataSourceID="DataSource1"

            DataTextField="Name" DataValueField="Id" />
<thp:DropDown ID="DropDown3" runat="server" Width="200" 


         DataTextField="Name" DataValueField="Id" OnClientChange="onDropDownChange" />

Here's a screenshot of what the above code would render:


Both controls support the following data events:

  • ItemDataBound - Fired after the object has been bound to an Item. The argument passes both the bound object (DataObject) and the ListItem.
  • NeedDataSource - Fired when there's no DataSourceID specified. This event is helpful when you want to manually populate the controls with your data. See the source code provided for specifics on this, you can use either Items collection or create custom list source (or both).


The code and usage is exactly as the DropDown control. Here's a screenshot of all of the above scenarios:


The styling in the attached project uses .skin files in the default theme. You can easily modify these to fit your needs. Everything can be styled.

I hope you find this code useful. I recommend this to anyone that wants to start developing custom controls as it has very important features implemented, such as the IPostBackDataHandler interface to pass data between postbacks in a custom manner. It also features some nice DataBinding examples and how you can use and modify these to perform specific tasks.


  • 6th May, 2009: Initial post


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


About the Author

Tomislav Markovski
Web Developer
Macedonia, the Republic of Macedonia, the Republic of
No Biography provided

You may also be interested in...


Comments and Discussions

SuggestionThis control doesn't work if there is an async postback in Web page Pin
Pham Dinh Truong10-Jul-13 19:08
memberPham Dinh Truong10-Jul-13 19:08 

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
Web02 | 2.8.180218.2 | Last Updated 6 May 2009
Article Copyright 2009 by Tomislav Markovski
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid