While I was developing a Blazor-based application I realized that Blazor doesn't have an out-of-the-box checkbox list control, so I thought why not create one of my own.In this blog I will give a step by step guide to create a Check Box List in Blazor.
Step 1
I will be using our Blazor Example project which I have created in my previous Blogs. This is about Futuristic Blazor application architecture. You can get the code from here.
Step 2
Open the BlazorComponents Project, right click on the Shared folder and select Option Add => Razor Component like below screenshot.

Step 3
On selecting that option you will get the following screen, give the name of the component as CheckBoxList as shown in the screenshot.

Step 4
Copy and paste the following code into the file,
- @typeparam TItem
- <div style=@Style>
- @if (Data != null)
- {
- foreach (var item in Data)
- {
- var Text = TextField?.Invoke(item);
- var Value = ValueField?.Invoke(item).ToString();
- bool Checked = false;
- if (SelectedValues.Contains(Value))
- {
- Checked = true;
- }
- <input type="checkbox" checked=@Checked
- @onchange="eventArgs => { CheckboxClicked(Value, eventArgs.Value); }" />
- @Text <br />
- }
- }
- @ChildContent
- </div>
- @code {
- //Data for the Checkbox
- [Parameter] public IEnumerable<TItem> Data { get; set; }
- // The field to be shown adjacent to checkbox
- [Parameter] public Func<TItem, string> TextField { get; set; }
- // The Value which checkbox will return when checked
- [Parameter] public Func<TItem, object> ValueField { get; set; }
- // CSS Style for the Checkbox container
- [Parameter] public string Style { get; set; }
- // Any childd content for the control (if needed)
- [Parameter] public RenderFragment ChildContent { get; set; }
- // The array which contains the list of selected checkboxs
- [Parameter] public List<string> SelectedValues { get; set; }
- //Method to update the selected value on click on checkbox
- public void CheckboxClicked(string aSelectedId, object aChecked)
- {
- if ((bool)aChecked)
- {
- if (!SelectedValues.Contains(aSelectedId))
- {
- SelectedValues.Add(aSelectedId);
- }
- }
- else
- {
- if (SelectedValues.Contains(aSelectedId))
- {
- SelectedValues.Remove(aSelectedId);
- }
- }
- StateHasChanged();
- }
- }
Let's understand the above code, the HTML part is basically code to generate the CheckBoxList on the basis of parameter Data which is a list of generic type TItem so that we can bind any object type list to the CheckBoxList. While creating the CheckBoxList the code also checks if the value is present in the SelectedValues list and marks the CheckBox Checked property based on that. This is basically for loading the checkbox list in edit mode.
I have taken these properties from SelectList control present in Blazorise UI library.The idea is to make this control part of that library some day.
Step 5
To use this CheckboxList control, create a new page Named CbListEx.razor in Pages folder following Step-2 & 3.

Step 6
Right click on the Pages folder again and select Option Add => Class like below screenshot.

Step 7
On selecting that option you will get the following screen, give the name of the class as CbListEx.razor.cs as shown in screenshot.

The idea here is to create a code behind class for the razor page and when we give the same name with .cs extension Visual Studio automatically groups the files together as shown in the below screenshot,

Step 8
Copy the following code in CbListEx.razor.cs file,


magy kamalPosted Jul 19, 2025, 8:27 PM
<DxListBox Data="@communicationOptions" TextFieldName="Name" SelectionMode="ListBoxSelectionMode.Multiple" ShowCheckboxes=true ShowSelectAllCheckbox="true" @bind-Values="SelectedCommunicationTypes" ValueFieldName="IDChoosingCommunicationType" CssClass="w-100" /> ShowSelectAllCheckbox no show
Adin AronsonPosted Apr 24, 2022, 5:28 PM
Hi. Could you explain how the two way binding is working in the CheckBoxList.razor component? I thought one needs to use an EventCallback. but your component updates the SelectedIds variable (SelectedValues="@SelectedIds") in the parent page without any problem. Thanks!