Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Dropdownlist

On my ASPX page I've added Dropdownlist.

Elements in this list are divided to groups by adding disabled list items:

ListItem separator = new ListItem("---My friends---", "");
separator.Attributes.Add("disabled", "true");
_ddUsersList.Items.Add(separator);

Those list items are grayed, I can't select it by mouse or by clicking cursor arrows(up/down). That is correct.

But problem is, that after clicking '-' key this list item is selected. I think that it is Dropdownlist bug, but I need to find some solution for this.

How to prevent selecting disabled ListItems by clicking first letter from its title? Or there is better way to create separators in Dropdownlist?

Edit: I've checked it after Nico G. comment. This problem happens in IE, not in Firefox. (I have no other browsers. Two is enought:) )

like image 437
Marek Kwiendacz Avatar asked Feb 13 '12 09:02

Marek Kwiendacz


2 Answers

that's a bug in IE. check this link Select, Option, Disabled And The JavaScript Solution.

like image 132
Nika G. Avatar answered Nov 14 '22 23:11

Nika G.


There are a number of different approaches in this question: Dropdownlist control with <optgroup>s for asp.net (webforms)? for adding Option Groups to a Dropdownlist control.

You can utilise the OptionGroups to create non-selectable separators which would look like the following in the source:

<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<optgroup label="----------"></optgroup>
<option>Option a</option>
<option>Option b</option>
<option>Option c</option>
</select>
like image 45
thudbutt Avatar answered Nov 15 '22 01:11

thudbutt