4

Possible Duplicate:
make drop down list item unselectable

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

Each item has a Heading that it's sorted on, 10 items under 1 heading (example). and I want to not allow the heading to be selected.

0

2 Answers 2

4

Try for each element you want to diable:

  ListItem i = DropDownList1.Items.FindByValue(str);
  i.Attributes.Add("style", "color:gray;");
  i.Attributes.Add("disabled", "true");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks kman :) You save my time
2

As long as your DropDownList is populated with items you can easily enable and disable them using the following property:

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

This will lead to the rendering them in HTML as non-selectable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.