# Edit Hierarchical Grids with Checkboxes

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Product version</td>
  <td>2025.1.227</td>
 </tr>
</table>

## Description

How can I edit boolean fields using checkboxes in hierarchical Grids?

## Solution

You can achieve this requirement using the following implementation:

1. Define a template column in the detail Grid that contains a checkbox element and set its `checked` attribute based on the value of the **IsCompleted** field:

   ```Razor HtmlHelper
   columns.Template(t => { })
   .ClientTemplate("<input type='checkbox' \\#= IsCompleted ? checked='checked':'' \\# class='chkbx' />")
   .HeaderTemplate("<input type='checkbox' id='masterCheckBox' onclick='checkAll(this)'/>").Width(200);
   ```

2. Handle the `click` event of the checkboxes and update the **IsCompleted** field based on the respective checkbox state:

   ```JS
   $(function () {
       $('\\#Orders_#=EmployeeID#').on('click', '.chkbx', function () {
           var checked = $(this).is(':checked');
           var grid = $('\\#Orders_#=EmployeeID#').data().kendoGrid;
           var dataItem = grid.dataItem($(this).closest('tr'));
           dataItem.set('IsCompleted', checked);
       });
   });

   function checkAll(ele) {
       var state = $(ele).is(':checked');
       var grid = $('\\#Orders_#=EmployeeID#').data().kendoGrid;
       $.each(grid.dataSource.view(), function () {
           if (this['IsCompleted'] != state)
               this.dirty=true;
           this['IsCompleted'] = state;
       });
       grid.refresh();
   }
   ```

To review the complete example, refer to the [project on how to create a template column with a checkbox that updates the underlying model when its state is changed in a hierarchical Grid](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridHierarchyEditingWithCheckboxes).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)
* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)
* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)
* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)
* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
