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>
VBProtected 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