Solved

Is Grouping Possible in asp.net dropdown list while databinding it?

Posted on 2009-06-30
3
318 Views
Last Modified: 2012-05-07
I need to bind a dropdownlist populating all the states of US and Canada, and I need to group them with headers as "US" and "Canada" which will be non selectable. Is that possible? Please help.
0
Comment
Question by:anindyas
  • 2
3 Comments
 
LVL 1

Expert Comment

by:annz7117
ID: 24749916
Using just a dropdownlist? mmm

 I guess not , have you tried with a second control , i mean, using a textbox or a combobox to select  or write :"US" or "Canada"?, and by that way you start filling the dropdownlist?, in other case ,you can use a query in the datasource with REPLACE function,  but this won't work as a header properly ...
0
 

Author Comment

by:anindyas
ID: 24752039
Yeah, that could be done. But the exact requirement is something like the "optgroup" property of html select list. But the problem is asp.net does not support this property.

I tried with dropdownlist control adapter, but my dropdownlist needs to be autopostback enabled. There is some problem happening regarding postback.

I need the exact rendering as the following does:
<option value="">Please select</option>
<optgroup label="Option A">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
</optgroup>
<optgroup label="Option B">
    <option value="a">A</option>
    <option value="b">B</option>
    <option value="c">C</option>
</optgroup>

Open in new window

0
 
LVL 1

Accepted Solution

by:
annz7117 earned 50 total points
ID: 24763676
Ok in asp.net  you can not add items  with </optgroup> , looks like this option is not anymore used from asp 2.0  , but if you need to do it specificaly that, you can do it with codebehind , just take a look of this article :
http://stackoverflow.com/questions/130020/dropdownlist-control-with-optgroups-for-asp-net
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question