Node Security

3 posts, 1 answers
  1. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 28 Sep 2010 Link to this post

    I have a scenario I'd like to know if you can help me with...

    I want to populate a TreeView using a Linq data source. This is because there is going to be another page that graphically allows admins to add/edit/delete/re-order nodes. When the admins work with this page, they will obviously be able to see all the nodes.

    Now on the actual page that the TreeView is going to be available to the general public, I want to be able to programatically limit which nodes are visible to the user based on active directory groups. Is there a way to turn nodes visible/hidden after the dataset has been returned from the Linq query? How would I accomplish this?

    Thanks for the assistance!
  2. Answer
    Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 29 Sep 2010 Link to this post

    Hello Philip Senechal,

    You can subscribe to the OnNodeDataBound event and show/hide nodes in the handler.

    Please take a look at this help topic.

    All the best,
    Veronica Milcheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 04 Oct 2010 Link to this post

    Thanks Veronica!

    I used that event and some creative code that reads through a List object stored in a session variable containing the current user's Active Directory group membership to turn nodes on and off. Works GREAT!

    protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
    {
        e.Node.Visible = false;
     
        EISDataContext db = new EISDataContext();
        var query = from navsecurity in db.tLeftNavSecurities
                    where navsecurity.NavID == int.Parse(e.Node.Value)
                    select navsecurity;
     
        foreach (tLeftNavSecurity navsecurity in query)
        {
            if ((Session["s_myADGroups"] as List<DataAccess.Group>).Find(delegate(DataAccess.Group g) { return g.Name == navsecurity.NavGrp; }) != null)
            {
                tLeftNav nav = db.tLeftNavs.Single(p => p.NavID == int.Parse(e.Node.Value));
     
                if (nav.NavActInd == "Y")
                {
                    e.Node.Visible = true;
                    e.Node.Expanded = true;
                }
            }
        }
    }
Back to Top