This is a migrated thread and some comments may be shown as answers.

RadTreeView in Master Page

1 Answer 47 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lubomir
Top achievements
Rank 1
Lubomir asked on 29 Sep 2012, 09:25 AM
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

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 03 Oct 2012, 01:51 PM
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.
Tags
TreeView
Asked by
Lubomir
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or