Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
Hello ALL,
I need to hide a node in asp.net depending on different user.
I have tried giving text as null, this way will work for child node but for parent node if text is given as null, text wont show up on page, but '+' sign in tree view is visible.

so I need some way to hide the parent node fully or I need to hide that + sign..

can anyone help!!!
Posted
Updated 20-Mar-13 20:49pm
v2
Comments
Sergey Alexandrovich Kryukov 21-Mar-13 2:16am    
It must be ASP.NET and not ASP.
—SA
salah9 21-Mar-13 2:50am    
I accept my mistake...
Sergey Alexandrovich Kryukov 21-Mar-13 2:51am    
As I can see, you actually fixed it. Great, thank you.
—SA
salah9 21-Mar-13 3:09am    
do you have solution for my problem???
Sergey Alexandrovich Kryukov 21-Mar-13 10:32am    
It looks like you already got it.
Cheers,
—SA

Hi salah,

You can use below code to hide node for the respective user, just pass the Index of node which u want to hide depending on different user.
C#
TreeView.Nodes.RemoveAt(NodeIndex)
 
Share this answer
 
v3
Try this:
C#
protected void Page_Load(object sender, EventArgs e)
{
  RemoveNodeRecurrently(TreeView1.Nodes, "YourTreeNodeText");
}

private void RemoveNodeRecurrently(TreeNodeCollection childNodeCollection, string text)
{
  foreach (TreeNode childNode in childNodeCollection)
  {
    if (childNode.ChildNodes.Count > 0)
      RemoveNodeRecurrently(childNode.ChildNodes, text);

    if (childNode.Text == text)
    {
      TreeNode parentNode = childNode.Parent;
      parentNode.ChildNodes.Remove(childNode);
      break;
    }
  }
}

Original Thread[^].


--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900