Edit this page

Bind Checkboxes in the MVC TreeList

Environment

Product 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() +
        "#}#"
    );
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy