riya
riya

Reputation: 125

Hide a parent node in TreeView if there are no child nodes

I have a TreeView on my .aspx page. I want to hide those parent node of a treeview when there are no child nodes.

Upvotes: 1

Views: 2121

Answers (1)

Maheep
Maheep

Reputation: 5605

See this article

protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
    SiteMapNode node = (SiteMapNode)e.Node.DataItem;
    if(node.HasChildNodes ==false && e.Node.Depth ==1)
    {
        TreeView1.Nodes[0].ChildNodes.Remove(e.Node);
    }
}

Upvotes: 1

Related Questions