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

duplicate nodes

1 Answer 65 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
rayala25
Top achievements
Rank 1
rayala25 asked on 02 Feb 2009, 08:01 PM
Hello,  I'm following sample of treeview LoadOnDemand,  i want to fill a tree with categories-subcategories data, but when i expand a categories node, it fills subcategories but it duplicates them. 

Using   ASP.NET AJAX Q2 2008 , WXP,  VS2008, VB  the code is a follows...

UPDATE:  Debugging the project ,  i know  "RadTreeView1_NodeExpand"  is fired twice , why is this happening?  or what can i do to fire this event just one time?




    Sub FillTree()  
        Dim connection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConStr2"))  
        Dim selectCommand As New SqlCommand("SELECT * FROM Categorias WHERE Codigo > 0", connection)  
        Dim adapter As New SqlDataAdapter(selectCommand)  
        Dim data As New DataTable()  
        adapter.Fill(data)  
        For Each row As DataRow In data.Rows  
            Dim node As New RadTreeNode()  
            node.Text = row("Descripcion")  
            node.Value = row("Codigo")  
            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack  
            RadTreeView1.Nodes.Add(node)  
        Next  
    End Sub  
 
    Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand  
        Dim connection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConStr2"))  
        Dim selectCommand As New SqlCommand("SELECT Children.Codigo as NodeId, Children.Descripcion AS NodeText, COUNT(Children.Codigo) AS ChildCount FROM Categorias LEFT JOIN Familias As Children ON Categorias.Codigo = Children.Categoria WHERE Children.Categoria = @parentId GROUP BY Children.Codigo, Children.Descripcion", connection)  
        selectCommand.Parameters.AddWithValue("parentId", e.Node.Value)  
        Dim adapter As New SqlDataAdapter(selectCommand)  
        Dim data As New DataTable()  
        adapter.Fill(data)  
        For Each row As DataRow In data.Rows  
            Dim node As New RadTreeNode()  
            node.Text = row("NodeText")  
            node.Value = row("NodeId")  
            If CInt(row("ChildCount")) > 0 Then  
                node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack  
            End If  
            e.Node.Nodes.Add(node)  
        Next  
        e.Node.Expanded = True 
    End Sub  
 

Thanks for any help. 

1 Answer, 1 is accepted

Sort by
0
rayala25
Top achievements
Rank 1
answered on 06 Feb 2009, 02:11 AM
Please any help!
Tags
TreeView
Asked by
rayala25
Top achievements
Rank 1
Answers by
rayala25
Top achievements
Rank 1
Share this question
or