Expanding nodes by lod on demand

4 posts, 0 answers
  1. Accord Dev Team
    Accord Dev Team avatar
    9 posts
    Member since:
    Jul 2007

    Posted 16 Apr 2014 Link to this post

    Hi,

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

    Could you help me?


    Thanks,
    Marcos
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Apr 2014 in reply to Accord Dev Team Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Accord Dev Team
    Accord Dev Team avatar
    9 posts
    Member since:
    Jul 2007

    Posted 17 Apr 2014 Link to this post

    Hi Shinu,

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

    Any idea?

    Thanks,
    Marcos
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Apr 2014 in reply to Accord Dev Team Link to this post

    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.
Back to Top