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
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
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"> </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