CheckBoxList
We use CheckBoxList to get multiple inputs from the user. It allows the user to select choices from the set of choices. The CheckBoxList control is an alternate control if you want to use several CheckBox controls.

Source
Making CheckBox using GUI
The Demo web form's initial step is to open the Forms Designer. You'll be able to drag controls from the toolbox to the Web form after that.
To access the Designer web form, right-click the Demo.aspx file in Solution Explorer and select View Designer from the menu.

You will see your Form Designer as shown below.

As seen below, drag the CheckBox control from the toolbox onto the Web Form.

By clicking on the CheckBox control, you'll be sent to the properties panel. Change the appropriate controls' ID properties to 'chkC' and 'chkASP'. Change the CheckBox control's text attribute to 'C#' as well. Change the value of the other CheckBox control to 'ASP.NET'.

Change the text property.

After you've made the modifications above, you'll get the following result.

CheckBox coding example
Following is a coding example of how to make CheckBoxes.
aspx file:
First, we have two individual CheckBoxes for the selection of multiple courses. Then we have a single CheckBox to opt for online. When a user clicks or deselects a CheckBox, you can call server-side c# code (postback). To do so, select AutoPostBack="true" and add OnCheckedChanged="handleCheckedChanged".
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
You can select multiple courses:<br />
<asp:CheckBox ID="aspnet" runat="server" Text="Asp.net" /><br />
<asp:CheckBox ID="csharp" runat="server" Text="CSharp" /><br />
<br />
<br />
CheckBox postback event:<br />
<asp:CheckBox ID="opt_online" runat="server" Text="Opt for online tutorial" AutoPostBack="true"
OnCheckedChanged="handleCheckedChanged" />
<br />
<br />
<asp:Label ID="displayMessage" runat="server" Style="color: Green; font-size: 18px; font-weight: bold;"></asp:Label>
</div>
</form>
</body>
</html>
cs file:
When the CheckBox with id opt_online gets selected or deselected, that is, if there is a change in opt_online value, the handleCheckedChanged method will be called. If the opt_online is ticked, the message will be displayed; otherwise, not.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void handleCheckedChanged(object sender, EventArgs e)
{
if (opt_online.Checked == true)
displayMessage.Text = "You have opted for online tutorial.";
else
displayMessage.Text = "";
}
}
Output:

FAQs
-
From where did the CheckBox class in ASP.NET inherit?
The inheritance of CheckBox can be explained as follows:
Object→ Control→WebControl→CheckBox
-
When should we use CheckBoxList control over multiple CheckBox controls?
We should choose CheckBoxList control over multiple CheckBox controls when we want convenient data-binding capabilities.
-
When do we prefer using several individual CheckBox controls over CheckBoxList control?
Individual CheckBox controls are preferred over CheckBoxList control when we want greater control over the layout.
-
What is the difference between the contents of the aspx and cs files?
Dynamic code (in this case, C# due to the .cs suffix on the file name) is usually placed in the .cs file as a "best practice" to keep dynamic code and static html separate. HTML, CSS, javascript, and other client-side controls are usually put in.aspx files.
-
What does the Checked property of CheckBox do?
Checked property is used to set the check state of the CheckBox control to either true or false.
Key Takeaways
From this article, we learned about CheckBox and CheckBoxList in ASP.NET. We saw how we could code it through a practical example.
But this is not enough; you need something extra to excel in web development truly. If you want to learn more about web development, you can read our articles or take our highly curated Web Development course.