0

i want to add multiple options in dropdown list with its category. Like list of designations on basis of its departments but department name should not be selectable. how to do this in asp.net? eg.

--IT--
Programmer
Tester
Analyst
--HR--
Manager
Executive-HR
Sr.Executive–HR Talent Acquisition

i forgot to mention, I am binding this from sqlserver database. and binding data in the dropdownlist.

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
Sushant
  • 391
  • 12
  • 28

3 Answers3

5

There is nothing to do with asp.net since it can be done with HTML

<select>
    <optgroup label="--IT--"></optgroup>
    <option value="0">Programmer</option>
    <option value="1">Tester</option>
    <option value="2">Analyst</option>
    <optgroup label="--HR--"></optgroup>
    <option value="3">Manager</option>
    <option value="4">Executive-HR</option>
    <option value="5">Sr.Executive–HR Talent Acquisition</option>
</select>
Nemoden
  • 8,816
  • 6
  • 41
  • 65
  • i got my mistake, dat i provide incomplete data. i forgot to mention, I am binding this from sqlserver database. and binding data in the dropdownlist. – Sushant Aug 24 '12 at 06:47
0

Use the HTML optgroup tag :

<select>
  <optgroup label="--IT--">
    <option value="Programmer">Programmer</option>
    <option value="Tester">Tester</option>
    <option value="Analyst">Analyst</option>
  </optgroup>
  <optgroup label="--HR--">
    <option value="Manager">Manager</option>
    <option value="Executive-HR">Executive-HR</option>
    <option value="Executive-HR-T">Sr.Executive–HR Talent Acquisition</option>
  </optgroup>
</select>

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
  • i got my mistake dat i provide incomplete data. i forgot to mention, I am binding this from sqlserver database. and binding data in the dropdownlist. – Sushant Aug 24 '12 at 06:46
  • 1
    We have no idea how you receive the data, or how your serverside is set up, so I think you'll have to figure out how to get the data from your database into HTML yourself. – adeneo Aug 24 '12 at 06:50
0

Hi Please refer this link

Just copy paste two folders and try to add dropdownlist in your project with this below type code

 ListItem item1 = new ListItem("Camel", "1");
        item1.Attributes["OptionGroup"] = "Mammals";

        ListItem item2 = new ListItem("Lion", "2");
        item2.Attributes["OptionGroup"] = "Mammals";

        ListItem item3 = new ListItem("Whale", "3");
        item3.Attributes["OptionGroup"] = "Mammals";

        ListItem item4 = new ListItem("Walrus", "4");
        item4.Attributes["OptionGroup"] = "Mammals";

        ListItem item5 = new ListItem("Velociraptor", "5");
        item5.Attributes["OptionGroup"] = "Dinosaurs";

        ListItem item6 = new ListItem("Allosaurus", "6");
        item6.Attributes["OptionGroup"] = "Dinosaurs";

        ListItem item7 = new ListItem("Triceratops", "7");
        item7.Attributes["OptionGroup"] = "Dinosaurs";

        ListItem item8 = new ListItem("Stegosaurus", "8");
        item8.Attributes["OptionGroup"] = "Dinosaurs";

        ListItem item9 = new ListItem("Tyrannosaurus", "9");
        item9.Attributes["OptionGroup"] = "Dinosaurs";


        DDLTest.Items.Add(item1);
        DDLTest.Items.Add(item2);
        DDLTest.Items.Add(item3);
        DDLTest.Items.Add(item4);
        DDLTest.Items.Add(item5);
        DDLTest.Items.Add(item6);
        DDLTest.Items.Add(item7);
        DDLTest.Items.Add(item8);
        DDLTest.Items.Add(item9);
Hardik Leuwa
  • 3,282
  • 3
  • 14
  • 28