The asp.net dropdown list has a specific value disabled for selection

Possible duplicate:
make the drop-down list of items unselected

I have an asp.net dropdown and would like to make some values ​​disabled for selection. We have a list of 10-100 items that will be in the drop-down list. Users need to select an item to perform the function.

Each element has a heading, which it sorts, 10 elements under 1 heading (example). and I don’t want the title to be selected.

+4
source share
2 answers

Try using every item you want to change:

ListItem i = DropDownList1.Items.FindByValue(str); i.Attributes.Add("style", "color:gray;"); i.Attributes.Add("disabled", "true"); 
+4
source

While your DropDownList is populating with elements, you can easily enable and disable them using the following property:

 DropDownList1.Items[1].Enabled = false; DropDownList1.Items[2].Enabled = true; 

This will cause them to appear in HTML as non-selectable.

+2
source

Source: https://habr.com/ru/post/1390422/


All Articles