Hide and visible CheckBoxList programmatically
The following asp.net c# example code demonstrate us how can we hide or visible a CheckBoxList control
programmatically at run time. CheckBoxList is an asp.net list web server control which provide a way to check/select
one or more items from items collection. CheckBoxList's each ListItem object render as a html CheckBox control. But in a CheckBoxList
all items act as a virtual group of CheckBox controls.
We can manage CheckBoxList visibility by accessing CheckBoxList built in property named 'Visible'. This Visible property ask a Boolean value. When we set this value to 'True', it render the CheckBoxList as a visible control in web browser; otherwise it hide CheckBoxList control from web browser. Visible property is better than Enabled property because it help us to provide more free space on web page. So, CheckBoxList Visible property true and false value allow us to switch between its visible and invisible state.
We can manage CheckBoxList visibility by accessing CheckBoxList built in property named 'Visible'. This Visible property ask a Boolean value. When we set this value to 'True', it render the CheckBoxList as a visible control in web browser; otherwise it hide CheckBoxList control from web browser. Visible property is better than Enabled property because it help us to provide more free space on web page. So, CheckBoxList Visible property true and false value allow us to switch between its visible and invisible state.
CheckBoxListVisisble.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
CheckBoxList1.Visible = false;
Label1.Text = "CheckBoxList Hide";
}
protected void Button2_Click(object sender, System.EventArgs e)
{
CheckBoxList1.Visible = true;
Label1.Text = "CheckBoxList Visible";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to hide, visible CheckBoxList programmatically</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">CheckBoxList: Hide, Visible</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="SeaGreen"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
Font-Bold="true"
ForeColor="Maroon"
Text="asp.net controls"
>
</asp:Label>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
>
<asp:ListItem>RadioButtonList</asp:ListItem>
<asp:ListItem>LoginView</asp:ListItem>
<asp:ListItem>Substitution</asp:ListItem>
<asp:ListItem>LoginName</asp:ListItem>
<asp:ListItem>XML</asp:ListItem>
</asp:CheckBoxList>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="Maroon"
Text="Hide CheckBoxList"
OnClick="Button1_Click"
/>
<asp:Button
ID="Button2"
runat="server"
Font-Bold="true"
ForeColor="Maroon"
Text="Visible CheckBoxList"
OnClick="Button2_Click"
/>
</div>
</form>
</body>
</html>


