TreeView ShowCheckBoxes All, None, Leaf, Parent and Root in

TreeView ShowCheckBoxes All, None, Leaf, Parent and Root Nodes
treeview control display hierarchical data. it is made up of nodes. treeview have a custom rendering feature that it has ability to render check boxes between the node text and image. treeview ShowCheckBoxes property allow us to display checkbox on node. checkbox allow the user to select multiple nodes from treeview control. this is a very useful feature when we allow user to choose some items from a hierarchical list.

we can specify which node types display checkbox using ShowCheckBoxes property. ShowCheckBoxes property use an enumeration of values such as TreeNodeTypes.All, TreeNodeTypes.Leaf, TreeNodeTypes.None, TreeNodeTypes.Parent and TreeNodeTypes.Leaf. TreeNodeTypes All display checkboxes for all nodes. Node type leaf display checkboxes for all leaf nodes. Node types None hide all checkboxes from treeview nodes. Node types Parent display checkboxes for parent nodes and node types root display checkboxes for only root nodes. the following c# example code demonstrate us how to show checkboxes in treeview control programmatically.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        TreeView1.ShowCheckBoxes = TreeNodeTypes.All;
        Label1.Text = "ShowCheckBoxes: All";

    protected void Button2_Click(object sender, System.EventArgs e) {
        TreeView1.ShowCheckBoxes = TreeNodeTypes.None;
        Label1.Text = "ShowCheckBoxes: None";

    protected void Button3_Click(object sender, System.EventArgs e) {
        TreeView1.ShowCheckBoxes = TreeNodeTypes.Leaf;
        Label1.Text = "ShowCheckboxes: Leaf";

    protected void Button4_Click(object sender, System.EventArgs e) {
        TreeView1.ShowCheckBoxes = TreeNodeTypes.Parent;
        Label1.Text = "ShowCheckBoxes: Parent";

    protected void Button5_Click(object sender, System.EventArgs e) {
        TreeView1.ShowCheckBoxes = TreeNodeTypes.Root;
        Label1.Text = "ShowCheckBoxes: Root";

<html xmlns="">
<head runat="server">
    <title>Asp.Net TreeView Example: programmatically ShowCheckBoxes All, None, Leaf, Parent, Root</title>
    <form id="form1" runat="server">
        <h2 style="color:Fuchsia">Dynamically Show CheckBoxes</h2>
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Teal"></asp:Label>
        <br /><br />
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
        <br />
        <asp:Button ID="Button1" runat="server" Text="Show CheckBox [All]" OnClick="Button1_Click" Font-Bold="true" ForeColor="Teal" />
        <asp:Button ID="Button2" runat="server" Text="Show CheckBox [None]" OnClick="Button2_Click" Font-Bold="true" ForeColor="Red" />
        <br /><br />
        <asp:Button ID="Button3" runat="server" Text="Show CheckBox [Leaf]" OnClick="Button3_Click"/>
        <asp:Button ID="Button4" runat="server" Text="Show CheckBox [Parent]" OnClick="Button4_Click"/>
        <asp:Button ID="Button5" runat="server" Text="Show CheckBox [Root]" OnClick="Button5_Click"/>
Web.sitemap file source code is here Web.sitemap

Related example