Enable disable CheckBoxList programmatically in asp.net c#

Enable and disable CheckBoxList programmatically
The following asp.net c# example code demonstrate us how can we enable and disable a CheckBoxList control's programmatically at run time. CheckBoxList is an asp.net list web server control. CheckBoxList is a virtual group of individual CheckBox controls. This is a specialized server control to manage multiple CheckBox controls as items collection. CheckBoxList control allow us to select/check one or more items at a time.

We can programmatically enable or disable a CheckBoxList server control at run time. .Net framework CheckBoxList Class 'Enabled' property allow us to switch between CheckBoxList's enable and disable state. Enabled property accept a Boolean value.

If we set the Enabled property value to 'True' then CheckBoxList control act as enabled control and if we set this property value to 'False' then CheckBoxList control appear as disabled control. Web users cannot select/check any item from a disable CheckBoxList control. A disabled control appear as dimmed in web browser. CheckBoxList control's Enabled property enable or disable all of its items, not partially.
CheckBoxListDisable.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        CheckBoxList1.Enabled = false;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        CheckBoxList1.Enabled = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to enable, disable CheckBoxList programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">CheckBoxList: Enable, Disable</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="Magenta"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:CheckBoxList 
             ID="CheckBoxList1"
             runat="server"
             >
             <asp:ListItem>RegularExpressionValidator</asp:ListItem>
             <asp:ListItem>Label</asp:ListItem>
             <asp:ListItem>Localize</asp:ListItem>
             <asp:ListItem>MultiView</asp:ListItem>
             <asp:ListItem>SiteMapDataSource</asp:ListItem>
        </asp:CheckBoxList>
        <br /><br />
        <asp:Button 
             ID="Button1"
             runat="server"
             Font-Bold="true"
             ForeColor="Magenta"
             Text="Disable CheckBoxList"
             OnClick="Button1_Click"
             />
        <asp:Button 
             ID="Button2"
             runat="server"
             Font-Bold="true"
             ForeColor="Magenta"
             Text="Enable CheckBoxList"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples