Click here to Skip to main content
13,347,671 members (49,390 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 17 Jul 2013

Poor Man's CheckBoxList using a DropDownList for ASP.NET/C#

, 17 Jul 2013
Rate this:
Please Sign up or sign in to vote.
Quick solution to convert a dropdownlist into a poor man's checkboxlist without having to import a 3rd party control.


Quick solution to convert a dropdownlist into a poor man's checkboxlist without having to import a 3rd party control.


I really like the dropdownlist in that it collapses nicely and has scrollbars. This is functionality I really need in a checkboxlist control. I looked for a long time at 3rd party controls and decided against them as you risk unpredictable issues and make portability more complex. For folks who like a home grown solution this will be extremely workable and easy to do.....

Using the code

Basically you need to commandeer the SelectedIndexChanged event of the dropdown list with the following code and include the function below it as well.  Any item that is clicked on will be preceded with a checkmark. If it is clicked on a second time the checkmark will be removed. If one item is left it will not be allowed to be unchecked.

To process the list, you need to wind through the items and look for any item that contains the checkmark character.

Also in my particular case I default a known item with a checkmark in the databound event of the dropdownlist that I am sure will always be in the list.

const char chkMark = (char)(0X2713); 
protected void MyDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    DropDownList TheDropDownList = (DropDownList)sender;
    bool itemUnchecked = false;
    int numberChecked = NumberofItemsChecked();
    if (TheDropDownList.SelectedItem.Text.Contains(chkMark) && numberChecked > 1)
        TheDropDownList.SelectedItem.Text = TheDropDownList.SelectedItem.Text.Substring(1);
        itemUnchecked = true;
    else if (!TheDropDownList.SelectedItem.Text.Contains(chkMark))
    TheDropDownList.SelectedItem.Text = chkMark + TheDropDownList.SelectedItem.Text;
    numberChecked = NumberofItemsChecked();
    //Display next checked item
    if (itemUnchecked)
        foreach (ListItem theItem in TheDropDownList.Items)
            if (theItem.Text.Contains(chkMark)) 
              { TheDropDownList.SelectedValue = theItem.Value; break; }
protected int NumberofItemsChecked()
    int numberChecked = 0;
    foreach (ListItem theItem in MyDropDownList.Items)
        if (theItem.Text.Contains(chkMark)) numberChecked++;
    return numberChecked;


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


About the Author

Web Developer
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
sumit_kapadia17-Jul-13 23:00
membersumit_kapadia17-Jul-13 23:00 

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.180111.1 | Last Updated 17 Jul 2013
Article Copyright 2013 by peter_x
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid