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

Gani_tpt 1,221 Reputation points
2022-06-29T09:56:08.2+00:00

I'm using Treeview control in asp.net.

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" >  
   <Nodes>  
            <asp:TreeNode Text="EmpDetails" Value="Emp. Details">  
  
              </asp:TreeNode>  
  </Nodes>  
</asp:TreeView>  
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
1,202 questions
No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,026 Reputation points
    2022-06-30T02:56:52.373+00:00

    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 17,296 Reputation points
    2022-06-29T12:07:58.833+00:00

    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">  
        <Nodes>  
            <asp:TreeNode Text="No PostBack" Value="No.Postback" SelectAction="None"></asp:TreeNode>  
            <asp:TreeNode Text="PostBack" Value="PostBack"></asp:TreeNode>  
        </Nodes>  
    </asp:TreeView>  
    

    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