DropDownTree HtmlHelper Overview

The Telerik UI DropDownTree HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI DropDownTree widget.

The DropDownTree represents an editor of hierarchical data, rendered in a tree-like structure, which provides multiple selection option and custom nodes.

Basic Configuration

  1. Make sure you followed all the steps from the introductory article on Telerik UI for ASP.NET MVC.
  2. Create a new action method which renders the view.

    public ActionResult Index()
    {
        return View();
    }
    
  3. Add a DropDownTree.

        @(Html.Kendo().DropDownTree()
            .Name("dropdowntree") // The name of the DropDownTree is mandatory. It specifies the "id" attribute of the DropDownTree.
            .Items(items =>
            {
                items.Add().Text("Root Item 1")
                    .Items(childred =>
                    {
                        childred.Add().Text("Child Item 1");
                        childred.Add().Text("Child Item 2");
                    });
                items.Add().Text("Root Item 2"); // Add an item with text "Item2".
            })
        )
    
        <%: Html.Kendo().DropDownTree()
            .Name("dropdowntree") // The name of the DropDownTree is mandatory. It specifies the "id" attribute of the DropDownTree.
            .Items(items =>
            {
                items.Add().Text("Root Item 1")
                    .Items(childred =>
                    {
                        childred.Add().Text("Child Item 1");
                        childred.Add().Text("Child Item 2");
                    });
                items.Add().Text("Root Item 2"); // Add an item with text "Item2".
            })
        %>
    

Functionality and Features

The DropDownTree provides options for Ajax binding.

Events

You can subscribe to all DropDownTree events. For a complete example on basic DropDownTree events, refer to the demo on using the events of the DropDownTree.

Handling by Handler Name

The following example demonstrates how to subscribe to events by a handler name.

    @(Html.Kendo().DropDownTree()
            .Name("dropdowntree")
            .Events(e => e
                .Expand("onExpand")
                .Collapse("onCollapse")
            )
    )
    <script>
        function onExpand() {
            // Handle the expand event.
        }

        function onCollapse() {
            // Handle the collapse event.
        }
    </script>
    <%: Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .Events(e => e
            .Expand("onExpand")
            .Collapse("onCollapse")
        )
    %>
    <script>
        function onExpand() {
            // Handle the expand event.
        }

        function onCollapse() {
            // Handle the collapse event.
        }
    </script>

Handling by Template Delegate

The following example demonstrates how to subscribe to events by a template delegate.

@(Html.Kendo().DropDownTree()
    .Name("dropdowntree")
    .Events(e => e
        .Expand(@<text>
        function() {
            // Handle the expand event inline.
        }
        </text>)
        .Collapse(@<text>
        function() {
            // Handle the collapse event inline.
        }
        </text>)
    )
)

Referencing Existing Instances

To reference an existing DropDownTree instance, use the jQuery.data() configuration option. Once a reference is established, use the DropDownTree client-side API to control its behavior.

// Place the following after the DropDownTree for ASP.NET MVC declaration.
<script>
    $(function() {
        // The Name() of the DropDownTree is used to get its client-side instance.
        var dropdowntree = $("#dropdowntree").data("kendoDropDownTree");
    });
</script>

See Also

In this article
Not finding the help you need? Improve this article