Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
currently i use code below at the client side to create the treeview.

XML
<asp:TreeView ID="TreeView1" runat="server">
       </asp:TreeView>


now, i plan to remove the code above and build it at code behind. i tried this code, but it doesn't work;
C#
TreeView TreeView1 = new TreeView();


for the reference, this is my code behind:
C#
TreeViewState state;
//TreeView TreeView1 = new TreeView();
protected void Page_Load(object sender, EventArgs e)
{
    state = new TreeViewState("TreeViewState");
    buildTree();
}

public void buildTree()
{
    //some code
}

private void TreeViewBind()
{
    if (state.IsSaved)
    {
        state.RestoreTreeView(TreeView1, "TreeViewState", HttpContext.Current);
    }
}
Posted
Updated 3-Jul-13 22:17pm
v5
Comments
Have you added the control to form like below...

this.Form.Controls.Add(TreeView1);
melvintcs 4-Jul-13 5:12am    
thanks a lot! stupid me missed this code..
Most welcome. :) I added this as an answer. Please accept.

Thanks,
Tadit
Thanks a lot for accepting the answer.

1 solution

Have you added the control to form like below?
C#
this.Form.Controls.Add(TreeView1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900