Solved

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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