Home - Forums-.NET - FlyTreeView (ASP.NET) - Recursively step through tree

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Recursively step through tree
Link Posted: 03-Sep-2007 04:26
I am attempting to move my various treeviews into an .ascx (user control) file for VS 2005. I have a tree, populated from data (sql) similar to below. I use the client code from one of the demos to 'reorder' the tree. I then use a submit button intending to run an sp to update the referencing ID in SQL (and, if my sneaky plan works, any other attriburtes I send along) The problem is that, when I dimension the child node items in the submit button click event the 'original' order is maintained. I assume, in the demo below, I should see the index value go 0,2,0,1 (parent, node 3, node 1, node 2) as I recusively step through the nodes. Instead the node 1 index (and all it's other attribuites) continue to be the first index after the parent. I don't want to do this on the client side 'move' event if possible, to much back and forth to the server. What am I doing wrong? parent - 1 - 2 - 3 parent - 3 - 1 - 2 Code behind Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dbConnection As New SqlConnection dbConnection.ConnectionString = ConfigurationManager.ConnectionStrings(\"con_walkaboutcanuck\").ConnectionString Dim sqlQuery As New SqlCommand(\"PhotosWithRank\", dbConnection) sqlQuery.CommandType = CommandType.StoredProcedure sqlQuery.Parameters.Add(New SqlParameter(\"@albumcatagoryid\", \"1\")) Dim hierarchicalData As IHierarchicalEnumerable = NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(TreeManager.NodesDSet(\"TestData\", sqlQuery), \"ID\", \"ParentID\") flyTreeView.DataSource = hierarchicalData flyTreeView.DataBind() End Sub Protected Sub bPostback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bPostback.Click Dim Tree As FlyTreeNodeCollection = flyTreeView.Nodes ParseTree(Tree.Item(0), Tree.Count) End Sub Function ParseTree(ByVal Tree As FlyTreeNode, ByVal e As Integer) For i As Integer = 0 To e - 1 Dim x As String = Tree.ChildNodes.Item(i).Text Dim ind As String = Tree.ChildNodes.Item(i).Index If Tree.ChildNodes.Item(i).ChildNodes.Count > 0 Then ' off to sql for some with attr ParseTree(Tree.ChildNodes.Item(i), Tree.ChildNodes.Item(i).ChildNodes.Count) End If Next End Function
Move Selected Node Up Down

Link Posted: 03-Sep-2007 04:31
You post was truncated. Please, post the rest.
Thanks.
Link Posted: 03-Sep-2007 04:42
So far, I can see you're rebinding the treeview every postback, so that the treeview state is cleared at Page_Load

Probably you should use

If Not IsPostBack Then
' bind treeview to data here
End If


So this will prevent your page from clearing treeview nodes and creating new one.