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

Maintain Treeview expanded and selected node state on postbackstate

3 Answers 209 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
murali
Top achievements
Rank 1
murali asked on 14 Mar 2011, 09:06 PM
Hello,

I am binding a treeview to a sitemap and I am trying to maintain the expanded and selected node state on a treeview. I have read the knowledgebase article regarding using a cookie to save the state of expanded nodes.How can I save the state of the currently selected node and re select the node on postback? Also, using the cookie approach I have noticed a decrease in performance when refreshing the screen.

3 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 15 Mar 2011, 10:51 AM
Hello mm,

You will need to use the same approach chosen for the expanded  nodes. Just wire OnSelect event and in the event handler persist which item is selected, something like this:

function selectNode(e) {
   $.cookie('SelectedNodes', $(e.item).text());
}
Then retrieve the selected item in the Action method, just like the expanded items. Last you will need to select item while rendering the treeview component:
item.Selected = ((string[])ViewData["SelectedNode"]).Contains(item.Text);

Kind regards,
Georgi Krustev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
murali
Top achievements
Rank 1
answered on 15 Mar 2011, 03:46 PM
Georgi,

Thanks for the quick response, saving the selected node is working now. I have another question though; The treeview that is bound to the sitemap is located in the site.master. The ViewData items used to refresh the treeview are loaded with the cookie data in the HOME controller.   So, does this mean that I will have to put the code to reload the viewdata items in
every controller that is used in the sitemap in order to refresh the treeview?

Thanks!
0
Georgi Krustev
Telerik team
answered on 18 Mar 2011, 10:26 AM
Hello Murali,

 Unfortunately the way you suggested is the appropriate one in this case. Nevertheless you can try to use Global FIlters, thus you can update ViewData in the Filter, and using global filter you will not need to apply this filter to all Action methods.

Regards,
Georgi Krustev
the Telerik team
Tags
TreeView
Asked by
murali
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
murali
Top achievements
Rank 1
Share this question
or