• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

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?
0
us1975mc
Asked:
us1975mc
  • 4
  • 3
2 Solutions
 
strickddCommented:
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
 
strickddCommented:
ListItem item = new ListItem("some group name", String.Empty);
item.Attributes["optgroup"] = "optgroup";
myDropDown.Items.Add(item);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now