Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a treeview which is binded from DB, suppose i select second node and create some operation on it, after that i am doing page postback and my selected node automatically get collapsed, i need to keep selected node expanded after page postback.

Please help me.

What I have tried:

I tried :-
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
ViewState["NodeValue"] = TreeView1.SelectedNode.Value;
}

And on button click event
protected void btnUploadFile_Click(object sender, EventArgs e)
{
TreeView1.SelectedNode.Value=ViewState["NodeValue"].ToString();
TreeView1.SelectedNode.PopulateOnDemand = true;
TreeView1.SelectedNode.Expanded = true;
}

here i tried to get selected node value using viewstate but still not working..
Posted
Updated 2-Oct-16 19:47pm
Comments
Karthik_Mahalingam 30-Sep-16 5:31am    
are you getting the value in ViewState["NodeValue"].ToString();
Dnyaneshwar Sable 24-Oct-16 1:21am    
Dear Karthik, i am getting the value in Viewstate but when my page postback at that time treeview loses its state and getting collapsed to Parent Node.
Karthik_Mahalingam 24-Oct-16 14:19pm    
then store the state in session.

1 solution

Hello
This is what I have used in my Project

C#
TreeListViewState.TreeListViewState _TreeListViewState = new TreeListViewState.TreeListViewState(ProductGroupTreeList);

_TreeListViewState.SaveState();

ProductGroupTreeList.DataSource = ...

_TreeListViewState.LoadState();


hope it works.
best regards
 
Share this answer
 
Comments
Karthik_Mahalingam 24-Oct-16 14:20pm    
5
Member 15066050 7-Feb-21 1:31am    
How to expand selected node of tree view in C# in web application form from database with navigate url at run time
I have posted my problem in this link
https://www.codeproject.com/Questions/5294104/How-to-expand-selected-node-of-tree-view-in-Csharp
Please anyone can solve my problem?

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