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

[Solved] Expand on Event with Load On Demand (LOD) Ajax version

1 Answer 179 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Phil C
Top achievements
Rank 2
Phil C asked on 19 Jun 2008, 11:40 AM
Hi, how do you fire the LOD NodeExpand event to force new children to be loaded and expanded on a single click (rather than the built-in doubleclick or click-on-lefthand-plussign)? Your LOD code is:

Protected Sub RadTreeView1_NodeExpand(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs) 
   Const sql As String = "SELECT Items.ItemID AS NodeId, Items.Name AS NodeText, COUNT(Children.ItemID) AS ChildCount FROM Items LEFT JOIN Items As Children ON Items.ItemID = Children.ParentId WHERE Items.ParentId = @parentId GROUP BY Items.ItemID, Items.Name" 
   Dim connection As New OleDbConnection(Properties.Settings.[Default].AccessConnection) 
   Dim adapter As New OleDbDataAdapter(sql, connection) 
   adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value) 
   Dim dataTable As New DataTable() 
   adapter.Fill(dataTable) 
   For Each row As DataRow In dataTable.Rows 
    Dim node As New RadTreeNode() 
    node.Text = row("NodeText").ToString() 
    node.Value = row("NodeId").ToString() 
    If Convert.ToInt32(row("ChildCount")) > 0 Then 
     node.ExpandMode = TreeNodeExpandMode.ServerSide 
    End If 
    e.Node.Nodes.Add(node) 
   Next 
   e.Node.Expanded = True 
   e.Node.ExpandMode = TreeNodeExpandMode.ClientSide 
  End Sub 

It doesn't matter if a server-side call is made, after all the data is needed to load so there is something to expand, otherwise using ClientNodeClicked to fire a node.toggle won't work because there's nothing loaded. Tried firing it from clientside (thought the node.expand may fire the serverside) but to no avail:

<script language="javascript"
function ClientNodeClicked(sender, eventArgs) 
   var node = eventArgs.get_node(); 
   node.Expand(); 
   node.toggle();      
   return true
</script> 

Have tried the serverside methods to no avail:

Public Sub RadTree1_OnServerNodeClicked(ByVal o As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTree1.NodeClick 
            e.Node.ExpandChildNodes() 
            e.Node.ExpandParentNodes() 
            e.Node.Selected = True 
            e.Node.Expanded = True 
            RadTree1.SelectedNode.ExpandChildNodes() 
            RadTree1.SelectedNode.ExpandParentNodes() 
            RadTree1.SelectedNode.Expanded = True 
End Sub 

So, can you fire the NodeExpand (with appropriate arguments), triggered by the client singleclick on the node? This would seem to be the most efficient (codewise) way, as other threads resort to callback panels etc and I can't see why this should be necessary. After all, if a double-click or click-on-plussign can fire it, why can't a single click?

1 Answer, 1 is accepted

Sort by
0
Phil C
Top achievements
Rank 2
answered on 22 Jun 2008, 04:59 PM
Sorted this with a support ticket as was short of time and needed a fix. The problem was I was missing the ExpandMode="ServerSideCallBack" in the treeview declaration, then it just needed a simple call to:

function onClientNodeClicked(sender, eventArgs) 
{  var node = eventArgs.get_node(); 
   //confirm("ClientNodeClicked"); 
   node.expand();     

Hope this helps someone!
Tags
TreeView
Asked by
Phil C
Top achievements
Rank 2
Answers by
Phil C
Top achievements
Rank 2
Share this question
or