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

Save expanded nodes in a masterPage

3 Answers 78 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jose antonio
Top achievements
Rank 1
jose antonio asked on 14 Dec 2010, 04:24 PM
Hi, I have a problem with a Radtreeview in a masterPage, I try to save the expanded nodes state in a Session variable and shows me InvalidOperationException and cannot create the xml file.
Session("myTreeView") = Tree1.GetXml
I want to save the treeview state and load it in other page like the nodes where in the first page.
Could you help me?
Thanks. 

3 Answers, 1 is accepted

Sort by
0
jose antonio
Top achievements
Rank 1
answered on 14 Dec 2010, 08:50 PM
I try to use the cookies code examples and nothing happens. This is my masterPage code. The error appears at the end of the code when I try to save in xml file the nodes.
Partial Class AbismoNet_master_MasterPage3
    Inherits System.Web.UI.MasterPage
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Tree1.Nodes.Clear()
            Dim varExplot As String = Session("Id_fabrica")
            Dim sql As String = ""
            Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
            sql = "SELECT * FROM wgm.V_BUSCAR_FABRICAS WHERE ID_FABRICA=" & varExplot & " "
            Dim adapter As New SqlDataAdapter(sql, connection)
            Dim dataTable As New DataTable()
            'PanelArbol.Visible = True
            adapter.Fill(dataTable)
            For Each row As DataRow In dataTable.Rows
                Dim node As New RadTreeNode()
                node.Text = row("NOMBRE_FCA").ToString()
                node.Value = row("ID_FABRICA").ToString()
                node.ExpandMode = True
                node.Expanded = True
                node.ExpandMode = TreeNodeExpandMode.ServerSide
                Tree1.Nodes.Add(node)
            Next
            LoadRootNodes(Tree1)
        End If
  
    End Sub
  
        Private Sub LoadRootNodes(ByVal treeView As RadTreeView)
        Dim varExplot As String = Session("Id_fabrica")
        Dim sql As String = ""
        Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
        sql = "SELECT * FROM wgm.V_BUSCAR_ZONAS WHERE ID_FABRICA=" & varExplot & " "
        Dim adapter As New SqlDataAdapter(sql, connection)
        Dim dataTable As New DataTable()
        'PanelArbol.Visible = True
        adapter.Fill(dataTable)
        For Each row As DataRow In dataTable.Rows
            Dim node As New RadTreeNode()
            node.Text = row("NOMBRE").ToString()
            node.Value = row("ID_ZONA").ToString()
            node.ImageUrl = "~/Abismonet/img/Z.png"
            node.ExpandMode = TreeNodeExpandMode.ServerSide
            node.ExpandMode = True
            Tree1.Nodes.Add(node)
        Next
        'CargarMenu()
    End Sub
  
    Protected Sub Tree1_NodeClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles Tree1.NodeClick
        Dim i As Integer = e.Node.Level
        Select Case i
            Case 0
                If e.Node.Nodes.Count > 0 Then
                    Exit Sub
                End If
                Dim sql As String
                sql = "SELECT SECCIONES.ID_SECCION AS NodeId, SECCIONES.NOMBRE AS NodeText, "
                sql = sql & " COUNT(SECCIONES.ID_SECCION) AS ChildCount FROM wgm.SECCIONES WHERE"
                sql = sql & " SECCIONES.ID_ZONA = @parentId AND ID_FABRICA = " & Session("Id_fabrica") & " GROUP BY SECCIONES.ID_SECCION,SECCIONES.NOMBRE"
                Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
                Dim adapter As New SqlDataAdapter(sql, connection)
                adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)
                For Each row As DataRow In dataTable.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("NodeText").ToString()
                    node.Value = row("NodeId").ToString()
                    node.ImageUrl = "~/Abismonet/img/S.png"
                    If Convert.ToInt32(row("ChildCount")) > 0 Then
                        node.ExpandMode = TreeNodeExpandMode.ServerSide
                    End If
                    e.Node.Nodes.Add(node)
                Next
  
            Case 1
                If e.Node.Nodes.Count > 0 Then
                    Exit Sub
                End If
                Dim sql As String
                sql = "SELECT DEPARTAMENTOS.ID_DEPARTAMENTO AS NodeId, DEPARTAMENTOS.NOMBRE AS NodeText,"
                sql = sql & " COUNT(DEPARTAMENTOS.ID_DEPARTAMENTO) AS ChildCount FROM wgm.DEPARTAMENTOS"
                sql = sql & " WHERE DEPARTAMENTOS.ID_SECCION = @parentId  AND ID_FABRICA = " & Session("Id_fabrica") & ""
                sql = sql & "GROUP BY DEPARTAMENTOS.ID_DEPARTAMENTO,DEPARTAMENTOS.NOMBRE"
                Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
                Dim adapter As New SqlDataAdapter(sql, connection)
                adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)
                For Each row As DataRow In dataTable.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("NodeText").ToString()
                    node.Value = row("NodeId").ToString()
                    node.ImageUrl = "~/Abismonet/img/D.png"
                    If Convert.ToInt32(row("ChildCount")) > 0 Then
                        node.ExpandMode = TreeNodeExpandMode.ServerSide
                    End If
                    e.Node.Nodes.Add(node)
                Next
            Case 2
                If e.Node.Nodes.Count > 0 Then
                    Exit Sub
                End If
                Dim sql As String
                sql = "SELECT MAQUINAS.ID_MAQUINA AS NodeId, MAQUINAS.NOMBRE AS NodeText, "
                sql = sql & " COUNT(MAQUINAS.ID_MAQUINA) AS ChildCount FROM wgm.MAQUINAS WHERE "
                sql = sql & "MAQUINAS.ID_DEPARTAMENTO = @parentId AND ID_FABRICA = " & Session("Id_fabrica") & " GROUP BY MAQUINAS.ID_MAQUINA,MAQUINAS.NOMBRE"
                Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
                Dim adapter As New SqlDataAdapter(sql, connection)
                adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)
                For Each row As DataRow In dataTable.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("NodeText").ToString()
                    node.Value = row("NodeId").ToString()
                    node.ImageUrl = "~/Abismonet/img/M.png"
                    If Convert.ToInt32(row("ChildCount")) > 0 Then
                        node.ExpandMode = TreeNodeExpandMode.ServerSide
                    End If
                    e.Node.Nodes.Add(node)
                Next
                'btnImprimir.Visible = True
            Case 3
                If e.Node.Nodes.Count > 0 Then
                    Exit Sub
                End If
                Dim sql As String
                sql = "SELECT EQUIPOS.ID_EQUIPO AS NodeId, EQUIPOS.NOMBRE AS NodeText, COUNT(EQUIPOS.ID_EQUIPO)"
                sql = sql & " AS ChildCount FROM wgm.EQUIPOS WHERE EQUIPOS.ID_MAQUINA = @parentId "
                sql = sql & " AND ID_FABRICA = " & Session("Id_fabrica") & " GROUP BY EQUIPOS.ID_EQUIPO,EQUIPOS.NOMBRE"
                Dim connection As SqlConnection = New SqlConnection(Session("Conexion"))
                Dim adapter As New SqlDataAdapter(sql, connection)
                adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value)
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)
                For Each row As DataRow In dataTable.Rows
                    Dim node As New RadTreeNode()
                    node.Text = row("NodeText").ToString()
                    node.Value = row("NodeId").ToString()
                    node.ImageUrl = "~/Abismonet/img/E.png"
                    If Convert.ToInt32(row("ChildCount")) > 0 Then
                        node.ExpandMode = TreeNodeExpandMode.ServerSide
                    End If
                    e.Node.Nodes.Add(node)
                Next
        End Select
        e.Node.Expanded = True
        e.Node.ExpandMode = TreeNodeExpandMode.ClientSide
        e.Node.PostBack  = False 
    End Sub
    Protected Sub Tree1_NodeDrop(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeDragDropEventArgs)
        If e.HtmlElementID = "ctl00_txtDrag" Then
            For Each node As RadTreeNode In e.DraggedNodes
                txtDrag.Text = node.Value
                Session("IdActivo") = node.Value
                txtDrag.ReadOnly = True
                Label1.Text = node.Text
                Session("Nivel") = node.Level
            Next
            If Session("IdActivo") = Session("Id_fabrica") Then
                Session("myTreeView") = Tree1.GetXml
                Response.Redirect("Fabricas.aspx")
            End If
end Sub
0
Helen
Telerik team
answered on 17 Dec 2010, 07:10 PM
Hi Jose,

Please try to attach to the NodeExpand server event and add the text and the value of the expanded nodes to the session. Then in the other page you may traverse trough all nodes, filter the expanded by value which is saved in the session and explicitly expand them.

Regards,
Helen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
jose antonio
Top achievements
Rank 1
answered on 20 Dec 2010, 09:35 AM
Ok, thanks for show me the road, Now I can save nodes.

Best Regards.
Tags
TreeView
Asked by
jose antonio
Top achievements
Rank 1
Answers by
jose antonio
Top achievements
Rank 1
Helen
Telerik team
Share this question
or