anindyas
asked on
Is Grouping Possible in asp.net dropdown list while databinding it?
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.
ASKER
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:
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ...