How to readonly or disabled Treeview Parent node while loading the page in ASP.NET

Gani_tpt 1,446 Reputation points

I'm using Treeview control in

I just want to make the parent node as readonly or disabled.

Remaining child node as it is. Like child node is navigating the URL. (we don't want to touch anything in child node).

how to do this,,?

<asp:TreeView ID="TreeView1" runat="server" ExpandDepth="1" >  
            <asp:TreeNode Text="EmpDetails" Value="Emp. Details">  
A set of technologies in the .NET Framework for building web applications and XML web services.
3,185 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,061 Reputation points

    Hi @Gani_tpt ,
    You could use "TreeNodeSelectAction" property. You need to foreach all nodes to find the parent node and then you could set the SelectAction "None".

      TreeView tv = (TreeView)FindControl("TreeView1");  
      tv.Nodes[0].SelectAction = TreeNodeSelectAction.None;  

    Best regards,
    Yijing Sun

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. AgaveJoe 25,761 Reputation points

    Your question is not clear. The TreeView is a navigation server control. I think you are actually asking how to stop the TreeView control from posting back?

    <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="1">  
            <asp:TreeNode Text="No PostBack" Value="No.Postback" SelectAction="None"></asp:TreeNode>  
            <asp:TreeNode Text="PostBack" Value="PostBack"></asp:TreeNode>  

    GaniTPT, you have a lot of post on these forums and I get the feeling you are not making an effort to learn the technology. It seems like you are copying and pasting code without understanding how the code, or server control in this case, works.

    TreeView Class
    TreeNode Class
    TreeNode.SelectAction Property