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?
Thanks for any help.
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.