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
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
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
Please read these article about Multiselect Dropdown in Asp.net 4.0 using C# and multi-select dropdownlist with checkboxes
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);
}
}
here is good example for multiple selection in dropdown list using check boxes
I hope it will helps you
Perhaps CheckBoxList control... Isn't it more suited for the multiple selection scenario?