Home All Groups Group Topic Archive Search About

How to Disabled node in Treeview

Author
20 Feb 2007 2:21 AM
Maria Paz
Hello,
In my web application, i use a treeview control to navigate.
I need to disabled node for Different roles.
How to do this?

Author
21 Feb 2007 2:08 PM
Mark Nelson
Maria Paz,

This is a bit tricky scenario. This feature is not supported out-of-box with
ASP.NET 2.0. I'm not sure how you can dynamically disable treeview nodes.

But i've found a work around for this. Instead of populating you treeview
with sitemap.xml, i populated with API's of Treeview. Using the API's you can
add or remove nodes  during the fly. You can use this as the base to set up
the security trimming logic. Please refer the following snippet of code.

hope this helps !

          // Let's assume this is the snippet  for the administrator and
administrator
         // has access to all the nodes
            TreeNode tn1 = new TreeNode("First Node");
            TreeView1.Nodes.Add(tn1);

            TreeNode tn2 = new TreeNode("Second Node");
            TreeView1.Nodes.Add(tn2);

            TreeNode tn3 = new TreeNode("Third Node");
            TreeView1.Nodes.Add(tn3);

            TreeNode tn4 = new TreeNode("Fourth Node");
            TreeView1.Nodes.Add(tn4);

            // Lets assume this is the snippet for your under privileged user
            // You dont want to display the nodes 2 and t
            TreeView1.Nodes.Remove(tn2);
            TreeView1.Nodes.Remove(tn4);




--
Thanks & Regards,
Mark Nelson


Show quoteHide quote
"Maria Paz" wrote:

> Hello,
> In my web application, i use a treeview control to navigate.
> I need to disabled node for Different roles.
> How to do this?
Author
21 Feb 2007 7:41 PM
Maria Paz
Thaks Mark.

But I found other solutions using a SiteMap and Treeview.

I read Walkthrough: Filtering Site-Map Nodes Based on Security Roles
in http://msdn2.microsoft.com/en-us/library/ms178429(vs.80).aspx

Thanks again

Show quoteHide quote
"Mark Nelson" wrote:

> Maria Paz,
>
> This is a bit tricky scenario. This feature is not supported out-of-box with
> ASP.NET 2.0. I'm not sure how you can dynamically disable treeview nodes.
>
> But i've found a work around for this. Instead of populating you treeview
> with sitemap.xml, i populated with API's of Treeview. Using the API's you can
>  add or remove nodes  during the fly. You can use this as the base to set up
> the security trimming logic. Please refer the following snippet of code.
>
> hope this helps !
>
>           // Let's assume this is the snippet  for the administrator and
> administrator
>          // has access to all the nodes
>             TreeNode tn1 = new TreeNode("First Node");
>             TreeView1.Nodes.Add(tn1);
>
>             TreeNode tn2 = new TreeNode("Second Node");
>             TreeView1.Nodes.Add(tn2);
>
>             TreeNode tn3 = new TreeNode("Third Node");
>             TreeView1.Nodes.Add(tn3);
>
>             TreeNode tn4 = new TreeNode("Fourth Node");
>             TreeView1.Nodes.Add(tn4);
>
>             // Lets assume this is the snippet for your under privileged user
>             // You dont want to display the nodes 2 and t
>             TreeView1.Nodes.Remove(tn2);
>             TreeView1.Nodes.Remove(tn4);
>
>
>
>
> --
> Thanks & Regards,
> Mark Nelson
>
>
> "Maria Paz" wrote:
>
> > Hello,
> > In my web application, i use a treeview control to navigate.
> > I need to disabled node for Different roles.
> > How to do this?