You must Sign In to post a response.
  • Category: ASP.NET

    Treeview node not expanding on clicking on text

    Hi,

    I have a tree view in which there are two child nodes with parentID 0 and a main node with no ID.


    Root Node
    0--> Child 1
    1--? SubChilds
    3--->SubChild1
    1--> Subchilds
    0--> Child 2
    2--> SubChilds
    2--> SubChilds

    The tree structure is as above. The problem is that whenever I click on Child 2 the Child 1 node gets expanded, I have checked using breakpoints and found out that whenever I click on Child 2 the sleectednode.text shows Child 1. How can I clear this?

    Thank & Regards,
    SaJ
  • #762110
    Hello Sajin,

    Refer the below code :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" ImageSet="Arrows"
    ontreenodeexpanded="TreeView1_TreeNodeExpanded"
    ontreenodecollapsed="TreeView1_TreeNodeCollapsed">
    <ParentNodeStyle Font-Bold="False" />
    <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
    <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
    HorizontalPadding="0px" VerticalPadding="0px" />
    <Nodes>
    <asp:TreeNode Text="Root" Value="Root Node">
    <asp:TreeNode Text="Child 1" Value="Child 1">
    <asp:TreeNode Text="Sub Childs 1" Value="Sub Childs 1"></asp:TreeNode>
    <asp:TreeNode Text="Sub Childs 2" Value="Sub Childs 2"></asp:TreeNode>
    <asp:TreeNode Text="Sub Childs 3" Value="Sub Childs 3"></asp:TreeNode>
    </asp:TreeNode>
    <asp:TreeNode Text="Child 2" Value="Child 2">
    <asp:TreeNode Text="Sub Childs 1" Value="Sub Childs 1"></asp:TreeNode>
    <asp:TreeNode Text="Sub Childs 2" Value="Sub Childs 2"></asp:TreeNode>
    </asp:TreeNode>
    </asp:TreeNode>
    </Nodes>
    <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
    HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
    </asp:TreeView>
    <br />
    <asp:Label ID="Message" runat="server"></asp:Label>
    </div>
    </form>
    </body>
    </html>


    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
    TreeNode Node = e.Node.Parent;
    if (Node != null)
    {
    TreeView1.ExpandAll();
    }
    Message.Text = "You expanded the " + "\"" + e.Node.Text + "\"" + " node.";
    }

    protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
    Message.Text = "You collapsed the " + "\"" + e.Node.Text + "\"" + " node.";
    }


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762112
    Hi,

    Thank you for the response,
    The problem is that I am binding the treeview directly from the SQL table by using a stored procedure. The tree works fine on clicking the + sign, but on clicking the text of the node it doesn't...

    Thanks & Regards,
    SaJ


Sign In to post your comments