Bind Checkboxes in the Kendo UI TreeList for ASP.NET MVC
Environment
Product | Progress® Telerik® UI TreeList for ASP.NET Core |
Operating System | Windows 10 64bit |
Browser | Google Chrome |
Browser Version | Versie 62.0.3202.94 |
.NET Framework | Version 4.7 |
Visual Studio Version | Visual Studio 2017 |
Preferred Language | C Sharp |
Description
How can I add a checkbox column to the TreeList which will set an initial checked or unchecked state of the checkboxes based on the model values?
Solution
Use the template
method of the TreeList column.
columns.Add().Field(e => e.CheckBoxColumnField).Template(
"#if(CheckBoxColumnField == true){#" +
Html.Kendo().CheckBox().Name("name#:CheckBoxColumnField#").HtmlAttributes(new { @class = "CheckBoxColumnField" }).Checked(true).ToHtmlString() +
"#}else{#" +
Html.Kendo().CheckBox().Name("name#:CheckBoxColumnField#").HtmlAttributes(new { @class = "CheckBoxColumnField" }).ToHtmlString() +
"#}#"
);