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

Duplicate Nodes getting added

5 Answers 178 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Madhu
Top achievements
Rank 1
Madhu asked on 01 Jul 2008, 02:02 PM
Hi,

I have two treeview controls, one is the source and another is the destination.
I populate the source treeview control dynamically only on first page load i.e not on Postback, like

If Not IsPostback() then

PopulateSourceTreeview()    ' Private subroutine to populate treeview               dynamically.

End If

But what's happening is once I drag a node from source to destination, some nodes in Source treeview is getting duplicated, i.e it's again being added, especially the ones that have child node. But the one which don't have child nodes are not getting duplicated.

thnx

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Jul 2008, 03:54 PM
Hi Madhu,

I am not sure where the problem comes from. Did you try tracing the drag and drop operation with the debugger? Maybe this would show why the nodes are duplicated. Additionally you can check this online example which demonstrates similar.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Madhu
Top achievements
Rank 1
answered on 01 Jul 2008, 07:11 PM
Yes. I started the debugger too, but couldn't figure it out.
Here are my code snippets:

<

table width=80% border=0 cellpadding=3 class=maintable2 align="center">

<tr>

<td>

<telerik:RadTreeView ID="RadTvwSource" runat="server" DragAndDrop="true" DragAndDropBetweenNodes="true" MultipleSelect="true" Skin="Vista">

</telerik:RadTreeView>

</td>

<td style="width:5px">&nbsp;</td>

<td>

<telerik:RadTreeView ID="RadTvwDestination" runat="server" DragAndDrop="true" DragAndDropBetweenNodes="true"

MultipleSelect="true" Skin="Vista">

</telerik:RadTreeView>

</td>

</tr>

</table>


.aspx.vb code
-----------------

Protected Sub RadTvwSource_NodeDrop(ByVal o As Object, ByVal e As Telerik.WebControls.RadTreeNodeEventArgs) Handles      RadTvwSource.NodeDrop

        If e.SourceDragNode.Category = e.DestDragNode.Category Then
            Dim sScript1 As String = ""
            sScript1 = "<Script language='javascript'>"
            sScript1 += "alert('You cannot add a source node over the destination node of same type category.')"
            sScript1 += "</script>"
            Page.RegisterClientScriptBlock("", sScript1)

            Exit Sub
        End If

        e.DestDragNode.Nodes.Add(e.SourceDragNode)
       
End Sub

Protected

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

objCoreLibCapacityManagement =

New core180Lib.core180Lib.core180CapacityManagement(strConnDB)

If Not IsPostBack Then

populateSiteList()

LoadRackTemplates()

End If

End Sub

Private Sub populateSiteList()

ddSites.Items.Clear()

ddSites.DataSource = objCoreLibCapacityManagement.getSiteList()

ddSites.DataTextField =

"SiteName"

ddSites.DataValueField =

"SiteID"

ddSites.DataBind()

ddSites.Items.Insert(0,

New ListItem("--Select--", ""))

End Sub

Private Sub LoadRackTemplates()

RadTvwSource.Nodes.Clear()

Dim dt As DataTable = objCoreLibCapacityManagement.getRackTemplateListForSiteEquipment()

For Each row As DataRow In dt.Rows

Dim node As New RadTreeNode()

node.Text = row(

"RackLabel")

node.Value = row(

"RackTemplateID")

node.Category = row(

"TemplateType")

If CInt(row("ChildCount")) > 0 Then

node.ExpandMode = ExpandMode.ServerSideCallBack

End If

RadTvwSource.Nodes.Add(node)

Next

 

'RadTreeView1.DataSource = objCoreLibCapacityManagement.getRackTemplateList()

'RadTreeView1.DataTextField = "RackLabel"

'RadTreeView1.DataValueField = "RackTemplateID"

'RadTreeView1.DataBind()

End Sub

Protected Sub RadTvwSource_NodeExpand(ByVal o As Object, ByVal e As Telerik.WebControls.RadTreeNodeEventArgs) Handles RadTvwSource.NodeExpand

'Dim strTemplateType As String = e.NodeClicked.Category

Dim dt As DataTable

Select Case e.NodeClicked.Category

Case "RACK"

dt = objCoreLibCapacityManagement.getShelfTemplateListForSiteEquipment(e.NodeClicked.Value)

Case "SHELF"

dt = objCoreLibCapacityManagement.getCardTemplateListForSiteEquipment(e.NodeClicked.Value)

End Select

If Not dt Is Nothing Then

For Each row As DataRow In dt.Rows

Dim node As New RadTreeNode()

node.Text = row(

"Text")

node.Value = row(

"Value")

node.Category = row(

"TemplateType")

If CInt(row("ChildCount")) > 0 Then

node.ExpandMode = ExpandMode.ServerSideCallBack

End If

e.NodeClicked.Nodes.Add(node)

Next

End If

 

End Sub

Protected Sub ddSites_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddSites.SelectedIndexChanged

 

RadTvwDestination.Nodes.Clear()

Dim RootNode As New RadTreeNode()

RootNode.Text = ddSites.SelectedItem.Text

RootNode.Value = ddSites.SelectedValue

RootNode.Category =

"SITE"

RadTvwDestination.Nodes.Add(Rootnode)

Dim dt As DataTable

dt = objCoreLibCapacityManagement.getRackInstancesList(ddSites.SelectedValue)

If Not dt Is Nothing Then

For Each row As DataRow In dt.Rows

Dim node As New RadTreeNode()

node.Text = row(

"Text")

node.Value = row(

"Value")

node.Category = row(

"TemplateType")

If CInt(row("ChildCount")) > 0 Then

node.ExpandMode = ExpandMode.ServerSideCallBack

End If

RootNode.Nodes.Add(node)

Next

End If

End Sub



thnx


0
Madhu
Top achievements
Rank 1
answered on 01 Jul 2008, 08:05 PM
Also I have one more problem. When I drag and drop a node from source to the destination treeview and change the style of newly created node on destination view  , the style of the corresponding dragged node from source treeview also changes which I don't want.

0
Madhu
Top achievements
Rank 1
answered on 01 Jul 2008, 09:36 PM
What is the link for online help of RadTreeview control for ASP.NET Ajax
0
Mallverkstan
Top achievements
Rank 2
answered on 16 Dec 2008, 03:27 PM
I had a similar problem. This thread helped: http://www.telerik.com/community/forums/aspnet-ajax/treeview/call-node-expand-on-demand-more-than-once.aspx
Tags
TreeView
Asked by
Madhu
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Madhu
Top achievements
Rank 1
Mallverkstan
Top achievements
Rank 2
Share this question
or