Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to create a custom control with multi select option. what i want is a dropdownlist whose contents all have text boxes to enable multiple selection. what i have done till now is i used a text box and image button to show as dropdownlist. And on clicking it, a panel will be opened below that will contain a checkbox list. i want to know how i can bind data to this custom control so that it will populate the checkbox list

C#
[ToolboxData("<{0}:CustomDropdown  runat="server"></{0}:CustomDropdown>")]
   public class CustomDropdown : CompositeControl
   {
       TextBox textBox;
       ImageButton button;
       CheckBoxList checkBox;
       Panel pnlForChkBox;
       HtmlGenericControl div = new HtmlGenericControl("div");

       protected override void CreateChildControls()
       {
           Controls.Clear();

           textBox = new TextBox();
           textBox.ID = "txtbox";

           button = new ImageButton();
           button.ID = "btn";
           button.ImageUrl = "~/images/CustomDropdown.png";
           button.ImageAlign = ImageAlign.Middle;
           button.Click += new ImageClickEventHandler(button_Click);
           button.Height = Unit.Pixel(22);

           checkBox = new CheckBoxList();
           checkBox.ID = "chkList";


           pnlForChkBox = new Panel();
           pnlForChkBox.ID = "pnlForChkbox";
           pnlForChkBox.Controls.Add(checkBox);
           pnlForChkBox.Style.Add("border", "black 1px solid");
           pnlForChkBox.Style.Add("overflow-y", "scroll");
           pnlForChkBox.Style.Add("overflow-x", "x:hidden");
           pnlForChkBox.Style.Add("width", "180px");
           pnlForChkBox.Style.Add("Height", "180px");
           pnlForChkBox.Visible = false;
           this.Controls.Add(textBox);
           this.Controls.Add(button);
           this.Controls.Add(pnlForChkBox);

       }
Posted
Updated 1-Jan-15 22:30pm
v3
Comments
Arjsrya 2-Jan-15 3:05am    
where are you getting data for multiple selection.?He is the example which retrives data from the database and bind it into the checkbox list.

http://www.thegeekyway.com/asp-net-basics-populate-checkboxlist-database-using-c-dotnet/
Malayali Coder 2-Jan-15 3:13am    
the link you have is to bind data to checkboxlist. i want to bind data to the custom control which has a checkboxlist in it.
Arjsrya 2-Jan-15 3:18am    
Don't understand.How can you attach the data to the custom control?Is it your control something like Gridview or Checkboxlist kind of?

I hope you are using few controls to build your own custom control.One of the controls what you have used is Checkboxlist.there you can bind the data.

share the code if possible.
Malayali Coder 2-Jan-15 4:53am    
yes one of the controls is a checkboxlist i want to enable some properties of checkboxlist like datasource ,databind, selecteditems etc as the property of the control i am trying to make

1 solution

There will be a custom dropdown control with checkbox is available on CodePlex with source code, you can review it and make appropriate changes accordingly to your control, or you can use that directly instead of building your own control...

http://dropdowncheckboxes.codeplex.com/[^]

or

DropDown and MultiselectDropDown Controls for ASP.NET[^]
 
Share this answer
 
Comments
Malayali Coder 3-Jan-15 6:20am    
i want to build my own control so i get the know how of the things
Tejas Vaishnav 5-Jan-15 0:57am    
That's why i have posted link form codeplex, from there you can download source code, and use that source code as your reference to create your own control.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900