Is it possible to disable an item in a dropdownlis

2019-07-18 03:52发布

Can I disable an item in a dropdownlist in c#?

For example, I have 2 dropdownlist combobox. Both of them consist of months (jan, feb, mar, apr, etc....) and both of them will function like a range of month in a certain year. When I choose apr on the 1st combobox, the second combobox can't choose jan, feb, mar

1条回答
2楼-- · 2019-07-18 04:10

Yes you can.

ListItems in your dropdownlist have an Enabled property. You can set this to false to disable them.

EDIT:

Sorry I made the assumption you were using WebForms (ASP.Net). For windows forms, you can take a look at this answer: Create WinForms ComboBox with non-selectable items - its the same principle but with some slight implementation details because Combobox Items collection is one of objects. Dropdownlist (the Web form equivalent) uses typed 'ListItem' objects.

HTH.

查看更多
登录 后发表回答