RadTreeView in Master Page

2 posts, 0 answers
  1. Lubomir
    Lubomir  avatar
    15 posts
    Member since:
    Sep 2012

    Posted 29 Sep 2012 Link to this post

    Hi, I can not keep the state of the tree in the Master page.
    This is my code
    public List<string> BindNodes
    {
        get
        {
            List<string> dataNodes = new List<string>();
            dataNodes.Add("item1");
            dataNodes.Add("item2");
            dataNodes.Add("item3");
            return dataNodes;
        }
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            BindTree();
    }
     
     
    private void BindTree()
    {
        List<string> data= BindNodes;
        for (int i = 0; i < data.Count; i++)
            LoadRecursive(data[i], null);
    }
     
    private void LoadRecursive(string item, RadTreeNode parentNode)
    {
        if (parentNode == null)
        {
            RadTreeNode childNode = new RadTreeNode();
            childNode.Value = "5";
            childNode.Text = item;
            childNode.Category = "category1";
            childNode.ExpandMode = TreeNodeExpandMode.ClientSide;
     
            tree.Nodes.Add(childNode);
            parentNode = childNode;
        }
        List<string> secondList= new List<string>();
        secondList.Add("sec1");
        secondList.Add("sec2");
     
        for (int i = 0; i < secondList.Count; i++)
        {
            RadTreeNode childNode = new RadTreeNode();
            childNode.Value = "5";
            childNode.Text = secondList[i];
            childNode.Category = "category2";
            childNode.ExpandMode = TreeNodeExpandMode.ClientSide;
            parentNode.Nodes.Add(childNode);
            //LoadRecursive(subSite[i], childNode);
        }
    }
     
    protected void tree_NodeClick(object sender, RadTreeNodeEventArgs e)
    {
       switch (tree.SelectedNode.Category.ToString())
        {
            case "category1":
                Response.Redirect("~/Member/Cat1.aspx?id=" + tree.SelectedValue);
                break;
            case "category2":
                Response.Redirect("~/Member/Cat2.aspx?id=" + tree.SelectedValue);
                break;
         
        }
     
    }
    I looked at other similar threads in the forum, but  couldn't do it
  2. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 03 Oct 2012 Link to this post

    Hello Lubo,

    Attached is a content page which I have tested locally. It contains the code you have provided me with and a simple button which causes a postback. As far as I have tested the RadTreeView behavior with a post back it works just fine. Would you let me know if I am missing something?

    All the best,
    Ivana
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top