Introduction
This tip shows you how to add OptGroup
support to your dropdown list control.
Using the Code
- Download the file in the attachment & add the two folders App_Browser & App_Code to your project.
- After that, use the following code to create & populate your dropdown List control.
ListItem item1 = new ListItem("A", "1");
item1.Attributes["OptionGroup"] = "Alphabet";
ListItem item2 = new ListItem("B", "2");
item2.Attributes["OptionGroup"] = "Alphabet";
ListItem item3 = new ListItem("One", "3");
item3.Attributes["OptionGroup"] = "Numbers";
ListItem item4 = new ListItem("Two", "4");
item4.Attributes["OptionGroup"] = "Numbers";
ddlItems.Items.Add(item1);
ddlItems.Items.Add(item2);
ddlItems.Items.Add(item3);
ddlItems.Items.Add(item4);