Solved

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

Posted on 2009-06-30
3
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

707 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