Home - Forums-.NET - FlyTreeView (ASP.NET) - gettign flytreeview.DataSource as nothing

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

gettign flytreeview.DataSource as nothing
Link Posted: 28-Jan-2008 23:14
I have a created page and want's to maintain the state of the treeview by fetching the datasource property inside a session variable and then re-assigning that variable after casting to treeview's datasource.

Like this


Sub MaintainACopy()
            Session("TV") = TV.DataSource
End Sub

Sub RevertToLastState()
          TV.DataSource = Session("TV")
End Sub


but i am getting      TV.DataSource as nothing.
Link Posted: 28-Jan-2008 23:27
How do you set the DataSource?

Is the TV.DataSource nothing at MaintainACopy or RevertToLastState?

Where do you call MaintainACopy from (I mean page life-cycle stage - init or page-load or prerender or saveviewstate or other stage)?
Link Posted: 29-Jan-2008 00:49
I am calling MaintainACopy() function in node moved event.
Link Posted: 29-Jan-2008 01:21
It looks like you try to get TV.DataSource before any databinding occurred.
Can you please also answer two other questions?
Link Posted: 29-Jan-2008 19:00
How do you set the DataSource?

NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(....)
TV.DataSource = hierarchicalData
TV.DataBind()

It occur when the data is bound with the control and is displaying properly.
Now when i move a node from TV postback occurs. Now in that node moved event I am trying to get that datasource

Is the TV.DataSource nothing at MaintainACopy or RevertToLastState?

Yes
TV.DataSource is nothing at MaintainACopy
RevertToLastState is about to use the session variable which is being populated by MaintainACopy() Function

Where do you call MaintainACopy from (I mean page life-cycle stage - init or page-load or prerender or saveviewstate or other stage)?

I am calling MaintainACopy() function in node moved event.
Link Posted: 29-Jan-2008 22:06
So you set DataSource, then user interacts with page and postback occurs. Then you're trying to get TV.DataSource.
Is it correct?

But treeview does not maintain DataSource object between postbacks. Instead, it maintains its settings and nodes.
DataSource is not guaranteed to be serializable and in most cases would take much traffic. So it is never saved/loaded from viewstate.

From my point of view, you can try to store nodes collection in a session state, and restore when required.
Like this:
' saving
Session("TV") = TV.Nodes.Clone()

' restoring
TV.Nodes.AddRange(Session("TV")
Link Posted: 30-Jan-2008 18:21
Hopefully this may help. Anyway thanks for your quick reply.