How to Disabled node in Treeview

M

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?
 
M

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top