Link to home
Start Free TrialLog in
Avatar of zandur
zandur

asked on

[ASP.NET] Disable particular items in a dropdownlist

I have a dropdownlist that I populate in the code-behind.

In this dropdownlist I want to disable some listitems to prevent the user from selecting them . they are in the list for clarification only.

Is this possible to do from the code behind?
Avatar of PraxisWeb
PraxisWeb

If you want the item to be visible, but not selectable your best bet is to make the items an <optgroup> tag.

here is an article that shows you how to create a control to do this:

http://www.aspnetmania.com/Code/Code/128.html

The article is in russian... but C# is the same everywhere in the world so the code is all you need :)
I would really suggest against using OPTGROUP because that is not what that tag is intended for ... unless grouping of OPTIONs is what you really need to do.

Instead I would recommend adding a disabled attribute to the individual OPTIONS that should be DISABLED:

myDropDownList.Items[0].Attributes.Add("disabled", "disabled");
ASKER CERTIFIED SOLUTION
Avatar of PraxisWeb
PraxisWeb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial