1

Possible Duplicate:
Multi-select dropdown list in ASP.NET

I am doing databinding to a dropdown and I want to allow multiple selection using a check box in side the drop down. How can I do that. thanks

Community
  • 1
  • 1
Mark
  • 2,720
  • 15
  • 56
  • 87

5 Answers5

1

A combo box is used to select one of many items, not many of many. This is why why it does not have a SelectedItems Property. Depending on your interface (example WPF) you could use a Data Binding Item Template. But I would strongly advise not to do this, it is bad practise and you are also hiding the multiple items the user has selected.

It you want to allow a user to select multiple items use a ListBox or ListView so the users can see what selections they have made

Andy Clark
  • 3,363
  • 7
  • 27
  • 42
1

Please read these article about Multiselect Dropdown in Asp.net 4.0 using C# and multi-select dropdownlist with checkboxes

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
1
public class CheckBoxDropDownList :
    System.Web.UI.WebControls.WebControl,INamingContainer
{
    protected override void CreateChildControls()
    {
        base.CreateChildControls ();
        DropDownList ddl=new DropDownList();
        ListItem li=new ListItem("");
        ddl.Items.Add(li);
        ddl.Width =new Unit(100);
        ddl.Attributes.Add("onmousedown", "showdiv()");
        ddl.Attributes.Add("onclick", "showdiv()");
        ddl.Attributes.Add("ondragover", "hidediv()");
        ddl.Attributes.Add("onmouseout", "hidediv()");

        CheckBoxList cbl=new CheckBoxList();
        cbl.Width=new Unit(80);

        ListItem li1=new ListItem("ListItem1");
        ListItem li2=new ListItem("ListItem2");
        ListItem li3=new ListItem("ListItem3");

        cbl.Items.Add(li1);
        cbl.Items.Add(li2);
        cbl.Items.Add(li3);

        System.Web.UI.HtmlControls.HtmlGenericControl div=new 
            System.Web.UI.HtmlControls.HtmlGenericControl("div");
        div.ID="serverdiv";
        div.Controls.Add(cbl);
        div.Style.Add("BORDER-RIGHT", "black 1px solid");
        div.Style.Add("BORDER-TOP", "black 1px solid");
        div.Style.Add("BORDER-LEFT", "black 1px solid");
        div.Style.Add("BORDER-BOTTOM", "black 1px solid");
        div.Style.Add("VISIBILITY", "hidden");

        this.Controls.Add(ddl);
        this.Controls.Add(div);
    }
}
sorpigal
  • 25,504
  • 8
  • 57
  • 75
SShebly
  • 2,043
  • 1
  • 21
  • 29
  • 8
    SShebly : If you posting someone elses answer, it will be better if you can reference the original answer. I found the same answer here. http://www.dotnet247.com/247reference/msgs/42/211693.aspx Please don't just copy and paste someone elses answer :) – huMpty duMpty Oct 27 '11 at 11:49
1

here is good example for multiple selection in dropdown list using check boxes

I hope it will helps you

rockyashkumar
  • 1,302
  • 4
  • 13
  • 24
0

Perhaps CheckBoxList control... Isn't it more suited for the multiple selection scenario?

Nika G.
  • 2,374
  • 1
  • 17
  • 18