Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now