how to hide expanding icon (+ sign) with nodes with no child

3 posts, 1 answers
  1. AratiS
    AratiS avatar
    18 posts
    Member since:
    Jun 2012

    Posted 28 Mar 2013 Link to this post


    I am using RadTreeView with server side load on demand. The issue I am having is I don't want the '+' sign to be displayed for a node if it doesn't have a child node. How can I achieve this with server side load on demand. Below is the code I am using to create root and child nodes.

     ASPX code:

    <telerik:RadTreeView runat="server" ID="RadTreeView1" OnNodeExpand="RadTreeView1_NodeExpand" >
                    <telerik:RadTreeViewContextMenu ID="CM" runat="server">
                    <telerik:RadMenuItem Value="CreateSibling" Text="Create Sibling">
                    <telerik:RadMenuItem Value="CreateChild" Text="Create Child">
                    <telerik:RadTreeViewContextMenu ID="EmptyCM" runat="server">

    c# code:

    protected void Page_Load(object sender, EventArgs e)
                    if (!Page.IsPostBack)
                        LoadRootNodes(RadTreeView1, TreeNodeExpandMode.ServerSide);
                catch (Exception ex)

    private static void LoadRootNodes(RadTreeView treeView, TreeNodeExpandMode expandMode)
                DataTable data = GetData(new SqlCommand("select Description,ID from Table1"));

                foreach (DataRow row in data.Rows)
                    RadTreeNode rootnode = new RadTreeNode();
                    rootnode.Text = row["Description"].ToString();
                    rootnode.Value = row["ID"].ToString();
                    rootnode.ContextMenuID = "CM";
                    rootnode.ExpandMode = expandMode;

     protected void RadTreeView1_NodeExpand(object sender,RadTreeNodeEventArgs e)
                if (e.Node.Nodes.Count == 0)
                    PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSide);

            private static void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode)
                DataTable data = GetChildNodes(e.Node.Value,e.Node.ContextMenuID);

                foreach (DataRow row in data.Rows)
                    RadTreeNode childnode = new RadTreeNode();
                    childnode.Text = row["Description"].ToString();
                    childnode.Value = row["ID"].ToString();
                    if (!(childnode.Value == e.Node.Value))
                        childnode.ExpandMode = expandMode;

                    childnode.ContextMenuID = "CM";
                if (e.Node.Nodes.Count > 0)
                    e.Node.Expanded = true;
                   e.Node.ExpandMode = TreeNodeExpandMode.ClientSide;
                    //e.Node.Expanded = false;
  2. Answer
    Nencho avatar
    1446 posts

    Posted 02 Apr 2013 Link to this post

    Hello Arati,

    Since you had implemented the Load On Demand functionality, you could not be aware if there are any child node for a certain node, before it is expanded. Therefor, the desired functionality could not be achieved initially, since a request to the DataBase should be fired to extract the child nodes, if any exist.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. DevCraft R3 2016 release webinar banner
  4. Bob
    Bob avatar
    3 posts
    Member since:
    May 2012

    Posted 06 May 2013 Link to this post

    In order to achieve the desired results, you have to return a column from your sql query that indicates if the record has any children. You can then use this value to determine whether or not to set ExpandMode.
    Not knowing what your table structure looks like, I'm just providing a sample query to return the number of children for a given record assuming some sort of ParentID is related to the IDs in the table.

        (select count(*) from Table1 where ParentID = t.ID) as Children
        Table1 t
        t.ParentID = @ID

    //Then in your code when you build the tree, check to see if the node
    //has any Children. If it does then set the ExpandMode
    //If it doesn't then don't set ExpandMode
    if ( row["Children"] != "0" )
        childNode.ExpandMode = expandMode;
Back to Top