Kendo Treeview with checkboxes, pre-select items on load and pass selected items on button click

3 posts, 1 answers
  1. Dayana
    Dayana avatar
    2 posts
    Member since:
    Feb 2016

    Posted 22 Apr 2016 Link to this post



    I am using kendo treeview with checkboxes in ASP .Net MVC. The datasource for the treeview is a list of item and want some of them to be selected on loading the treeview and then I want to pass the newly selected items to the controller. I can achieve each one of the two separately(with a line of code for each functionality), but they seem to be mutually exclusive.


    This is my code for the view:

                            .Checkboxes(x => x.CheckChildren(true))
                            .CheckboxTemplate("<input type='checkbox' name='checkedFiles[#= #]' value='#= #' #if(item.IsChecked){# checked #}#/>")
                            .Events(events => events.DataBound("onDataBound"))
                            .Checkboxes(x => x.Name("PrescriptionProductInstructions"))                        
                            .DataSource(source => source.Read(read => read.Action("GetInstructions", "Note", new { productId = Model.ProductId, personId = Model.PersonId }))))

             function onDataBound() {


    The first bold line of code helps me pre-select some item when loading the tree and the second line of code helps me pass the list of ids of the selected items.


    My question is whether I can have both functionalities as the same time? If yes, how?


    Thanks in advance.




    Dayana Hadzhipetrova

  2. Answer
    Daniel avatar
    2231 posts

    Posted 26 Apr 2016 Link to this post


    If you need to use template and set specific name to the input then you should set the name in the template:
    .CheckboxTemplate("<input type='checkbox' name='PrescriptionProductInstructions' value='#= #' #if(item.IsChecked){# checked #}#/>")

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Dayana
    Dayana avatar
    2 posts
    Member since:
    Feb 2016

    Posted 26 Apr 2016 Link to this post

    Thanks for the reply. It all works now.





Back to Top