Disable specific items in a CheckboxList

techora picture techora · Feb 11, 2015 · Viewed 7.4k times · Source

I am running through a set of data, which will populate a CheckBoxList. I want to display all the items in the list but certain ones will be disabled as they don't qualify (their status equals Inactive). How do I set an item to disabled (Enabled = false) in the code behind like this?

if (node.SelectSingleNode("Status") == "Inactive")
   {
     customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
   }
else
   {
     customerList.Items.Add(new ListItem(displayName, displayValue));  // ENABLED
   }

Answer

JamesCarters picture JamesCarters · Feb 11, 2015
if (node.SelectSingleNode("Status") == "Inactive")
   {
     customerList.Items.Add(new ListItem{Name=displayName, Value= displayValue, Enabled= false}); // DISABLED
   }
else
   {
     customerList.Items.Add(new ListItem(displayName, displayValue));  // ENABLED
   }`