TreeView State Between Postback
-
Is there a way to retain the layout of the TreeView (e.g. which nodes are expanded and which are not) between postbacks. If I set a certain expansion level, it will expand all of the nodes to that level. If I set that to zero, everything is collapsed after the postback even though I've expanded the treeview to drill down to the item I'm working on. This would make the treeview almost pointless if there is no way to retain where you are currently navigation wise. Any ideas? Thanks for your help. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
Is there a way to retain the layout of the TreeView (e.g. which nodes are expanded and which are not) between postbacks. If I set a certain expansion level, it will expand all of the nodes to that level. If I set that to zero, everything is collapsed after the postback even though I've expanded the treeview to drill down to the item I'm working on. This would make the treeview almost pointless if there is no way to retain where you are currently navigation wise. Any ideas? Thanks for your help. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
Hi Matt, Actually, the TreeView control retains its state on postback, but if you happen to call the Expand method of the TreeView control, all the tree nodes are expanded based on the specified level. To drill down to the node that you are working on, you may consider using the method of the TreeNode instead of the TreeView.
-
Hi Matt, Actually, the TreeView control retains its state on postback, but if you happen to call the Expand method of the TreeView control, all the tree nodes are expanded based on the specified level. To drill down to the node that you are working on, you may consider using the method of the TreeNode instead of the TreeView.
Thanks for your response. I appreciate it. I'm not able to get the behavior that you have mentioned. I went back through my code and made sure I'm never calling expand or collapse and I still have all nodes collapsed when I click one of my links in the view. The only other possibilities I can think of are: 1) My ExpandDepth property is set to 0 2) I am loading the data dynamically when !IsPostBack Any other ideas? Thanks. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
Thanks for your response. I appreciate it. I'm not able to get the behavior that you have mentioned. I went back through my code and made sure I'm never calling expand or collapse and I still have all nodes collapsed when I click one of my links in the view. The only other possibilities I can think of are: 1) My ExpandDepth property is set to 0 2) I am loading the data dynamically when !IsPostBack Any other ideas? Thanks. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
Sorry for my late reply because of the weekend, if you already manage to solve your issue, you can skip my below questions: + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack. + How do you set the SelectAction property of the TreeNode. + I guess that I may easily figure out the cause when I see your code snippets.
-
Sorry for my late reply because of the weekend, if you already manage to solve your issue, you can skip my below questions: + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack. + How do you set the SelectAction property of the TreeNode. + I guess that I may easily figure out the cause when I see your code snippets.
minhpc_bk wrote:
+ Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack.
I load all of the nodes in the Page_Load with checking !IsPostBack
minhpc_bk wrote:
+ How do you set the SelectAction property of the TreeNode.
It doesn't look like I'm setting the SelectAction property, so whatever the default is.
minhpc_bk wrote:
+ I guess that I may easily figure out the cause when I see your code snippets.
Code snippet wise, there's really not much to show. I simply call LoadNavTree() which loads data into each of my six root nodes. I have a data access layer that returns a list of objects--one type of object for each of the six root nodes. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
minhpc_bk wrote:
+ Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack.
I load all of the nodes in the Page_Load with checking !IsPostBack
minhpc_bk wrote:
+ How do you set the SelectAction property of the TreeNode.
It doesn't look like I'm setting the SelectAction property, so whatever the default is.
minhpc_bk wrote:
+ I guess that I may easily figure out the cause when I see your code snippets.
Code snippet wise, there's really not much to show. I simply call LoadNavTree() which loads data into each of my six root nodes. I have a data access layer that returns a list of objects--one type of object for each of the six root nodes. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall
-
Do you set the value for the TreeNodes when you load data into the nodes? Also do they have different values or the same value?
They might have the same value, but a different ValuePath. That is, some top level nodes have children with the same values as other top level nodes. The path to each node, however, is always unique. -Matt
------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall