locked
Multiple selection on dropdownlist???

    Question

  • Hi!

        I would like to know if it's possible to select multiple values on a dropdownlist. I've already seen something that looks like a checkboxlist in a dropdownlist, I mean, at first it looks like a dropdownlist, and when you click the button, it appears a checkboxlist, where you can select as many values as you want.

       How can I do something like this?

     

              Thank you!

    Monday, May 22, 2006 6:50 PM

Answers

  •  

      Hi,

      You must write your own control... the DropDownList which is found in the System.Web.UI.Controls will render a <select><option...><option...></select> HTML code and have no chance to add checkboxes to the <option> tags.

      If you write your own control, you may develop something similar with a drop down list using a simple read-only TextBox, and a button which shows or hides a DIV with all items. If the DIV has the following style: "overflow: auto; width: ..; height: " it will keep the width and height and will display scrollbars if there are many items displayed in it.

      Best, Radu.

    Monday, May 22, 2006 8:15 PM

All replies

  •  

      Hi,

      You must write your own control... the DropDownList which is found in the System.Web.UI.Controls will render a <select><option...><option...></select> HTML code and have no chance to add checkboxes to the <option> tags.

      If you write your own control, you may develop something similar with a drop down list using a simple read-only TextBox, and a button which shows or hides a DIV with all items. If the DIV has the following style: "overflow: auto; width: ..; height: " it will keep the width and height and will display scrollbars if there are many items displayed in it.

      Best, Radu.

    Monday, May 22, 2006 8:15 PM
  • Your other choice is to use the HTML select box, set the multiple property to multiple and then get the value from Request.Forms.
    Tuesday, May 23, 2006 2:07 PM
  • Hi,

    1.   Create a CheckBoxList (i.e. cbl)

    2.   Create its SelectedIndexChanged event (cbl_ SelectedIndexChanged (…)).

    3.   Create a DataSet (i.e. ds)

    4.   Fill the DataSet with data

    5.   Assign the DataSet to the DataSource of the CheckBoxList (cbl.DataSourece = ds)

    6.   Bind the DataSet to the CheckBoxList (cbl.DataBind ())

    7.   Write code for the SelectedIndexChanged event. It must look for  the selected items  of the cbl and take the necessary actions.

    Remark:

    The CheckBoxList displays only the first column of the DataSet table preceded of check boxes. Therefore this column must contain all necessary data for further actions.

    I have an example on the site: http://www.wwv-it.com/WebServicesNet/CalendarDemos2.aspx.

    Sorry, the site is on German because it deals with holidays and vacations of Germans.  

     

    Have a fun!

    Valentin

    MCP C#

    Do not hesitate to contact me!

    www.wwv-it.eu

    valentin.welter@t-online.de

    Sunday, June 04, 2006 5:41 PM
  • Use a listbox. <asp:ListBox runat="server"></asp:ListBox>
    Thursday, May 31, 2007 6:29 PM
  • hi,

    i have 2 dropdowns,but if i selected the value in first dropdown it shows field id,in the same way if i selected value 2nd dropdown is different it should show different field id, but if i select any value in 2nd dropdown it is showing the same field id .means it is working based on first dropdown.

    can any one please help me.

    on selection of 2 dropdowns it shows different field id's based on value selection....

    its urgent please help me...!

    regards,

    rahul


    Thursday, March 08, 2012 6:49 AM