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

Expanding nodes by lod on demand

3 Answers 17 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Accord Dev Team
Top achievements
Rank 1
Accord Dev Team asked on 16 Apr 2014, 01:35 PM
Hi,

I need to emulate the expand node by lod on demand through js or vb.net code.

Could you help me?


Thanks,
Marcos

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 17 Apr 2014, 05:35 AM
Hi Horacio Judeikin,

I guess that you want to expand a RadTreeNode which loaded by LoadOnDeamd. You can try the following VB.net Code snippet to expand the RadTreeNode on the Button onClick event.

VB:
Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
    Dim node As RadTreeNode = TryCast(RadTreeView1.Nodes.FindNodeByText("Politics"), RadTreeNode)
    node.Expanded = True
End Sub
 
Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
0
Accord Dev Team
Top achievements
Rank 1
answered on 17 Apr 2014, 05:30 PM
Hi Shinu,

I tried it and it does not work. Only works when the node is clientside.

Any idea?

Thanks,
Marcos
0
Shinu
Top achievements
Rank 1
answered on 19 Apr 2014, 05:38 AM
Hi Horacio Judeikin,

Please have a look into the sample code snippet which works fine at my end. Please try to replicate the problem in this code for further help.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" Height="300px" Width="100%"
    OnNodeExpand="RadTreeView1_NodeExpand">
</telerik:RadTreeView>
<telerik:RadButton ID="RadButton1" runat="server" Text="Expand" OnClick="RadButton1_Click">
</telerik:RadButton>

VB:
Protected Sub Page_Load(sender As Object, e As EventArgs)
    If Not Page.IsPostBack Then
        LoadRootNodes(RadTreeView1, TreeNodeExpandMode.ServerSideCallBack)
    End If
End Sub
Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)
    PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSideCallBack)
End Sub
Private Shared Sub PopulateNodeOnDemand(e As RadTreeNodeEventArgs, expandMode As TreeNodeExpandMode)
    Dim data As DataTable = GetChildNodes(e.Node.Value)
    For Each row As DataRow In data.Rows
        Dim node As New RadTreeNode()
        node.Text = row("text").ToString()
        node.Value = row("id").ToString()
        e.Node.Nodes.Add(node)
    Next
    e.Node.Expanded = True
End Sub
Private Shared Function GetChildNodes(parentId As String) As DataTable
    Dim selectCommand As New SqlCommand((Convert.ToString("select id,text from Details where parentid='") & parentId) + "'")
    Return GetData(selectCommand)
End Function
Private Shared Function GetData(selectCommand As SqlCommand) As DataTable
    selectCommand.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Dim adapter As New SqlDataAdapter(selectCommand)
    Dim data As New DataTable()
    adapter.Fill(data)
    Return data
End Function
Private Shared Sub LoadRootNodes(treeView As RadTreeView, expandMode As TreeNodeExpandMode)
    Dim data As DataTable = GetData(New SqlCommand("SELECT * FROM Details WHERE parentid IS NULL"))
    For Each row As DataRow In data.Rows
        Dim node As New RadTreeNode()
        node.Text = row("text").ToString()
        node.Value = row("id").ToString()
        node.ExpandMode = expandMode
        treeView.Nodes.Add(node)
    Next
End Sub
Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
    Dim node As RadTreeNode = TryCast(RadTreeView1.Nodes.FindNodeByText("Politics"), RadTreeNode)
    node.Expanded = True
End Sub

Thanks,
Shinu.
Tags
TreeView
Asked by
Accord Dev Team
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Accord Dev Team
Top achievements
Rank 1
Share this question
or