Perform two actions on node text click?

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    25 posts
    Member since:
    Aug 2011

    Posted 28 Jun 2012 Link to this post

    I have a treeview that is set to load on demand. When the node text is clicked I want to both expand the node if it is expandable and trigger the Node Click event in code behind. below is what I have so far. Is this even possible?

        Protected Sub radprojecttree_NodeExpand(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgsHandles radprojecttree.NodeExpand         
            If (Not SiteUser Is NothingThen             
                BSRMaster.navtree.NavTree_InitNodes(Nothing, e.Node)         
            End If     
        End Sub     
     Sub radprojecttree_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgsHandles radprojecttree.NodeClick         
            Dim ts As String = e.Node.Attributes("contentpage")         
            radpancontentholder.ContentUrl = ts             
            Me.radprojecttree_NodeExpand(sender, e)           
        End Sub
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jun 2012 Link to this post

    Hi Mathew,

    Try the following code snippet to achieve your scenario.

    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("name").ToString()
            node.Value = row("id").ToString()
            If Convert.ToInt32(row("ChildrenCount")) > 0 Then
                node.ExpandMode = expandMode
            End If
        e.Node.Expanded = True
    End Sub
    Protected Sub radprojecttree_NodeClick(sender As Object, e As RadTreeNodeEventArgs)
        If e.Node.Nodes.Count = 0 Then
            PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSide)
        End If
    End Sub

    Hope this helps.

Back to Top