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

Update other controls in NodeExpand event

3 Answers 35 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 03 Dec 2014, 01:28 PM
Hi

I've got a a TreeView which I populate programmatically in the Page_Load event. While creating nodes, I also specify a NodeExpand event 
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
This fires my TreeView_NodeExpand event when a node is expanded which is good so far. In the event, I am trying to populate a ListView by setting it's DataSource and calling it's DataBind() method. But the ListView never populates. In fact, I tried with a dummy label for which the text is being updated in the NodeExpand event but the label doesn't update. 
I've even tried adding AjaxManager to the page and setting the UpdatedControlId to the listview. That didn't work either.
Please could you point out if I am missing anything here.

Thanks
Rama

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 08 Dec 2014, 08:53 AM
Hi Rama,

Please paste your code here, so we can see what are you doing.

Thanks.

Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rama
Top achievements
Rank 1
answered on 08 Dec 2014, 09:22 AM
Hi Hristo

Thanks for the reply - here is my code

When I debug, the quick watch shows correct values. i.e., on node expand event, PopulateContentsTable is executing correctly with the right datatable being bound to the listview but the listview doesn't show up on the front end. This is same with or without the AjaxManager. I even tried NeedDataSource event of the listview.

<telerik:RadTreeView ID="RadTreeView1" runat="server" Height="400px" Skin="Metro" ShowLineImages="false"
OnClientNodeExpanding="TreeViewNodeExpanding" OnClientNodeCollapsing="TreeViewNodeCollapsing"
OnClientNodeClicked="ClientNodeClicked">
</telerik:RadTreeView>
 
<telerik:RadListView runat="server" ID="FolderContentsListView">
<LayoutTemplate>
  <table id="itemPlaceholderContainer" runat="server" border="0" cellspacing="0" cellpadding="0">
    <tr id="itemPlaceholder" runat="server">
    </tr>
  </table>
 </LayoutTemplate>
 <ItemTemplate>
   <tr>
     <th align="left">
       <asp:Label ID="ItemNameLabel" runat="server" Text='<%#Eval("ItemName") %>' />
     </th>
     </tr>
     <tr style="height: 10px">
       <td></td>
     </tr>
    </ItemTemplate>
   </telerik:RadListView>
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
  <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadTreeView1">
      <UpdatedControls>
        <telerik:AjaxUpdatedControl ControlID="FolderContentsListView" />
      </UpdatedControls>                   
    </telerik:AjaxSetting>
  </AjaxSettings>
</telerik:RadAjaxManager>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Page.IsPostBack Then
            CreateTreeView()
        End If
End Sub
 
Private Sub CreateTreeView()
        Dim directories As String() = Directory.GetDirectories("C:\My Folder")
        For Each directory As String In directories
            Dim node As New RadTreeNode(Path.GetFileName(directory))
            node.Value = "C:\My Folder" + "\" + Path.GetFileName(directory)
            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
            RadTreeView1.Nodes.Add(node)
        Next
End Sub

Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand
        CreateSubNodes(e.Node.Value, e.Node)
        PopulateContentsTable(e.Node.Value)
End Sub
 
Private Sub CreateSubNodes(ByVal virtualPath As String, ByVal parentNode As RadTreeNode)
        Dim directories As String() = Directory.GetDirectories(virtualPath)
        For Each directory As String In directories
            Dim node As New RadTreeNode(Path.GetFileName(directory))
            node.Value = virtualPath + "/" + Path.GetFileName(directory)
            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
            parentNode.Nodes.Add(node)
        Next
End Sub
 
Private Sub PopulateContentsTable(ByVal virtualPath As String)
        Dim directories As String() = Directory.GetDirectories(virtualPath)
        Dim dtContents As New DataTable()
        dtContents.Columns.Add("ItemName")
        For Each directory As String In directories
            Dim dr As DataRow = dtContents.NewRow
            dr("ItemName") = Path.GetFileName(directory)
            dtContents.Rows.Add(dr)
            dtContents.AcceptChanges()
        Next
 
        FolderContentsListView.DataSource = dtContents
        FolderContentsListView.Databind()
End Sub

0
Hristo Valyavicharski
Telerik team
answered on 11 Dec 2014, 10:00 AM
Hi Rama,

Try to set the data source in the OnDataSourceNeeded event of the ListView:
http://www.telerik.com/help/aspnet-ajax/listview-getting-familiar-with-server-side-api.html

Protected Sub FolderContentsListView_NeedDataSource(sender As Object, e As RadListViewNeedDataSourceEventArgs)
    Dim directories As String() = Directory.GetDirectories("C:\My Folder\New folder")
    Dim dtContents As New DataTable()
    dtContents.Columns.Add("ItemName")
    For Each directory As String In directories
        Dim dr As DataRow = dtContents.NewRow
        dr("ItemName") = Path.GetFileName(directory)
        dtContents.Rows.Add(dr)
        dtContents.AcceptChanges()
    Next
 
    FolderContentsListView.DataSource = dtContents
End Sub


Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
Rama
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Rama
Top achievements
Rank 1
Share this question
or