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

Tree view Reapeating the Child Nodes

3 Answers 72 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ricky
Top achievements
Rank 2
Ricky asked on 28 Jul 2008, 11:06 PM
Hi

I have problem with generating the tree view from database table. The code is as following

ASPX

<telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="Vista"

OnNodeExpand="RadTreeView1_NodeExpand" >

</telerik:RadTreeView>

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

LoadRootNodes()

End If

End Sub



Private Sub LoadRootNodes()

Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("MYConnection").ConnectionString)

Dim selectCommand As New SqlCommand("SELECT * FROM tblA order by tp1", connection)

Dim adapter As New SqlDataAdapter(selectCommand)

Dim data As New DataTable()

adapter.Fill(data)

Dim counter As Integer

counter = 1

For Each row As DataRow In data.Rows

Dim node As New RadTreeNode()

node.Text = row(

"colA").ToString + " . " + row("ColB")

node.Value = row(

"ColC").ToString

node.ExpandMode = TreeNodeExpandMode.ServerSide

RadTreeView1.Nodes.Add(node)

counter += 1

Next

e Sub LoadRootNodes() 

End

Sub

Protected Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand

'If Not Me.Page.IsPostBack Then

Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("MYConnection").ConnectionString)

Dim selectCommand As New SqlCommand("SELECT distinct * FROM tblB WHERE achild = @a order by Sequence ", connection)

selectCommand.Parameters.AddWithValue(

"a", 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("ColD").ToString

node.Value = row(

"ColE").ToString

node.ExpandMode = TreeNodeExpandMode.ServerSide

e.Node.Nodes.Add(node)

Next

e.Node.Expanded =

True

e.Node.ExpandMode = TreeNodeExpandMode.ClientSide

End Sub



which loads the preant nodes from the database. 

Now the problem is when I Expand the tree view it Double up the child nodes.

Can anyone help regarding this.
Thanks
Ricky

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 30 Jul 2008, 03:52 PM
Hi Ricky,

It seems that you have subscribed twice to the NodeExpand event - once in the aspx of the page and once in code behind with the Handles clause - hence the Nodes get added two times.

Please remove one of the subscriptions to resolve the problem.

Regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ricky
Top achievements
Rank 2
answered on 30 Jul 2008, 10:51 PM
Hi Simon 

You can see from the code provided there is no linking to any data source on the aspx page. The problem is when i expand the parent node the event repeated twice. Now i have solved it using session variables. But this is not the proper solution for it.

Thanks
Ricky

0
Atanas Korchev
Telerik team
answered on 31 Jul 2008, 06:10 AM
Hi Ricky,

You seem to have subscribed twice to the NodeExpand event - first via the OnNodeExpand attribute and second via the Handles clause.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Ricky
Top achievements
Rank 2
Answers by
Simon
Telerik team
Ricky
Top achievements
Rank 2
Atanas Korchev
Telerik team
Share this question
or