Error in Dropdownlist

On my ASPX page, I added a Dropdownlist.

Elements in this list are divided into groups, adding disabled list items:

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

These list items are grayed out, I can not select it with the mouse or by clicking the cursor arrows (up / down). It is right.

But the problem is that after clicking the "-" button, this list item is selected. I think this is a Dropdownlist error, but I need to find some solution for this.

How to prevent the selection of disabled ListItems by clicking the first letter of its name? Or is there a better way to create separators in Dropdownlist?

Edit: I checked it after Niko's comment. This issue occurs in IE, not Firefox. (I have no other browsers. Two is enough :))

+7
source share
2 answers

what a bug in IE. check this link Choose, Option, Disabled and JavaScript Solution .

+1
source

There are several different approaches to this question: Dropdownlist control with <optgroup> s for asp.net (webforms)? to add groups of options to the Dropdownlist control.

You can use OptionGroups to create nonselectable delimiters that look like this 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> 
+1
source

All Articles