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

Reload treeview on button click

1 Answer 151 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Pratik
Top achievements
Rank 1
Pratik asked on 07 Apr 2011, 07:45 AM
Hi All,
i want to reload treeview on button click

means i want to call "RadTreeView1_NodeExpand" event on button click

.aspx code
<asp:UpdatePanel ID="StepUpdatePanel" runat="server">   
                                   <ContentTemplate>  
                                       <telerik:RadTreeView ID="trvSteps"  runat="server" Height="400px" Style="border: 1px solid #CBE7F5;"
                                           OnNodeExpand="RadTreeView1_NodeExpand" OnDataBinding="RadTreeView1_NodeExpand">
                                            <DataBindings>
                                               <telerik:RadTreeNodeBinding Expanded="True" />
                                           </DataBindings>
                                       </telerik:RadTreeView>
                                      <%-- <asp:TreeView ID="trvSteps" runat="server" ShowLines="true" ExpandDepth="0" SelectedNodeStyle-BackColor="LightBlue" >                                                                      
                                       </asp:TreeView>--%>
                                   </ContentTemplate>
                                   <Triggers>
                                       <asp:AsyncPostBackTrigger ControlID="btnReloadTreeview" EventName="Click"  />
                                    </Triggers>
                               </asp:UpdatePanel>

Code Behind Code

Protected Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
        Dim objFileRouteStep As Business.FileRouteStep
        Dim dt As DataTable
        Try
 
            objFileRouteStep = New Business.FileRouteStep
            objFileRouteStep.Fields.FileRouteID.FileRouteID = hdnRouteID.Value.ToString()
            objFileRouteStep.Fields.Methods.AddInputParameter("@MonitoringDirectoryID", System.Data.SqlDbType.Int, 18, hdnMDirectoryID.Value)
            dt = objFileRouteStep.GetFileRouteStepDataTable(Data.FileRouteStep.SqlProcedures.USP_select_Step_ByFileRouteID)
 
            If (trvSteps.Nodes.Count = 0) Then
                Dim rootNode As New RadTreeNode("Root")
                rootNode.Value = "0"
                'rootNode.ImageUrl = "~/TreeView/Img/Vista/folder.png"
 
                rootNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                trvSteps.Nodes.Add(rootNode)
                BindTreeToDirectory(e.Node.Value, e.Node)
            End If
 
 
 
        Catch ex As Exception
 
        End Try
    End Sub
 
    Private Sub BindTreeToDirectory(ByVal StepID As String, ByVal parentNode As RadTreeNode)
        Dim objFileRouteStep As Business.FileRouteStep
        Dim dt As DataTable
        Try
            dt = New DataTable
 
            If (StepID = "0") Then
                objFileRouteStep = New Business.FileRouteStep
                objFileRouteStep.Fields.FileRouteID.FileRouteID = hdnRouteID.Value.ToString()
                objFileRouteStep.Fields.Methods.AddInputParameter("@MonitoringDirectoryID", System.Data.SqlDbType.Int, 18, hdnMDirectoryID.Value)
                dt = objFileRouteStep.GetFileRouteStepDataTable(Data.FileRouteStep.SqlProcedures.USP_select_Step_ByFileRouteID)
 
                For Each dr As DataRow In dt.Rows
                    Dim node As New RadTreeNode(dr("Step").ToString() + "-" + dr("Desc").ToString(), dr("StepID").ToString(), "javascript:clickNode(this, '" + dr("StepID").ToString() + "');")
                    node.Value = dr("StepID").ToString()
 
                    If (dr("SubNode").ToString() = "0") Then
                    Else
                        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                    End If
 
 
                    parentNode.Nodes.Add(node)
 
                Next
            Else
                objFileRouteStep = New Business.FileRouteStep
 
                objFileRouteStep.Fields.Methods.AddInputParameter("@FileRouteID", System.Data.SqlDbType.Int, 18, StepID)
                dt = objFileRouteStep.GetFileRouteStepDataTable(Data.FileRouteStep.SqlProcedures.USP_select_childStep_ByFileRouteID)
 
                For Each dr As DataRow In dt.Rows
                    'If (dr("ParentID").ToString() = virtualPath.ToString()) Then
                    Dim node As New RadTreeNode(dr("Step").ToString() + "-" + dr("Desc").ToString(), dr("StepID").ToString(), "javascript:clickNode(this, '" + dr("StepID").ToString() + "');")
                    node.Value = dr("StepID").ToString()
                    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                    parentNode.Nodes.Add(node)
                    'End If
                Next
 
            End If
        Catch ex As Exception
        Finally
            objFileRouteStep = Nothing
            dt = Nothing
        End Try
 
    End Sub
Please help

Thanks in Advance
Pratik Asthana

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 12 Apr 2011, 12:01 PM
Hello Pratik,

To call the RadTreeView1_NodeExpand event on button click you can use the following event handler:
aspx:
<telerik:RadTreeView runat="Server" ID="RadTreeView1" Skin="Outlook" TabIndex="1"
            OnNodeExpand="RadTreeView1_NodeExpand">
        </telerik:RadTreeView>
        
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="height: 26px"
            Text="Button" />

vb:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Page.IsPostBack Then
            Dim rootNode As New RadTreeNode("Examples")
            rootNode.ExpandMode = TreeNodeExpandMode.ServerSide
            RadTreeView1.Nodes.Add(rootNode)
        End If
    End Sub
 
    
     
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        RadTreeView1_NodeExpand(RadTreeView1, New RadTreeNodeEventArgs(RadTreeView1.Nodes(0)))
        RadTreeView1.Nodes(0).Expanded = True
    End Sub
 
 
    Protected Sub RadTreeView1_NodeExpand(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand
        e.Node.Nodes.Add(New RadTreeNode("one"))
 
    End Sub

Kind regards,
Kate
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
TreeView
Asked by
Pratik
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or