OptGroups

I have figured out the render code for using optgroups in asp.net but I can't seem to figure out how to populate the dropdownlist.  Any suggestions or examples?
us1975mcAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
optgroups are a little "wonky" in .Net. This post is one i've used in the past, but it is still a little weird with postbacks and stuff: http://weblogs.asp.net/jeff/archive/2006/12/27/dropdownlist-with-optgroup.aspx
0
 
us1975mcAuthor Commented:
I did find that site, but have had troubling following it.  I am don't understand how to populate the dropdownlist.
0
 
strickddConnect With a Mentor Commented:
ListItem item = new ListItem("some group name", String.Empty);
item.Attributes["optgroup"] = "optgroup";
myDropDown.Items.Add(item);
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
us1975mcAuthor Commented:
Where does this code go?
0
 
strickddCommented:
when you need to add an item to the list, that's where you put this code. For example:

ListItem item;

foreach(string val in MyListOfItems)
{
item = new ListItem(val, val);
item.Attributes["optgroup"] = "MyOptGroupName";
myDropDown.Items.Add(item);
}
0
 
us1975mcAuthor Commented:
Thanks.  Let me give it a try.
0
 
us1975mcAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.