I have some items in a CheckedListBox
, I want to disable the CheckBox
of first item in it.
i.e. I want to disable the first item in the CheckedListBox
, because I want to tell the user visually that option is not available.
chkBoxlist. DataValueField = "state"; Then you can use ValueField to disable your checkboxlist item in terms of the state value in your Page_Load event by if else cause.
We can make a checkbox disabled in HTML using the disabled attribute. We assign the disabled attribute to an input to disable that input. We can also use the jQuery prop() method to change the disabled attribute of an input to true.
Combining 2 of the above partial answers worked great for me. Add your items to the list with:
myCheckedListBox.Items.Add(myItem, myState);
Where myState is CheckState.Indeterminate for items that should be disabled. Then add an event handler to keep those items from being changed:
myCheckedListBox.ItemCheck += (s, e) => { if (e.CurrentValue == CheckState.Indeterminate) e.NewValue = CheckState.Indeterminate; };
This does not allow you to use 'Indeterminate' in this list for its normal purpose but it does give a look very similar to what one would expect for a disabled item and it provides the correct behavior!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With