Solved

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

Posted on 2009-06-30
3
317 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

803 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