Right now when I expand a node in my webtree and there are no child nodes to be added, it displays a node with the text "No data returned from server". That makes sense since there's obviously no data being returned, but how can I prevent it from displaying that rather than displaying the expanded node as a leaf node? I'm using version 7.1 of the WebTree with ManualSmartCallbacks. I've included the code I'm using below. I've also tried using javascript to get the count of child nodes and cancelling postback if the count is zero, but the CancelPostBack doesn't seem to work.
Dim userInfoID As Long = CType(node.DataPath, Long)
Node.Nodes.Clear()
If dtReports.Rows.Count > 0 Then
node.Nodes.Add(newNode)
Next
node.Expanded = True
Else
node.Expanded = False
node.ShowExpand = False
End If
End Sub
Me.PopulateNode(e.Node)
Thanks. I used the count in the initial SQL query as you suggested. I was hoping there was a better way, but this will work.
Hello,
This is really a very interesting and complex case. The best solution here would probably be to not display an expand (plus) image at all for nodes that do not have children, e.g. set their ShowExpand property to false. However, you do not know if a node has children when you populate them on demand - you will have to make one additional SQL Select for each node to find that out. If you use related tables, or single self-referencing table, you can also use somewhat complex join clauses to find this in a single query, for example
SELECT Nodes.Id AS NodeId, Nodes.Text AS NodeText, COUNT(Children.Id) AS HasChildren FROM Nodes LEFT JOIN Nodes Children ON Nodes.Id = Children.ParentId WHERE Nodes.ParentId = {0} GROUP BY Nodes.Id, Nodes.Text
(where you can replace {0} with the ID of the parent node) and then use the "HasChildren" result to determine of the ShowExpand property should be true or false. But this is really complicated and can even get more complicated, depending on your SQL setup.
In your approach I am afraid setting node.Expanded to False and node.ShowExpand = false has no effect since it is done on the server after the actual request.
Alternatively, in the case where no child nodes are present, I can suggest adding a new single dummy node (probably Enabled = False) with node.Text = "Any message you wish". This will override the default "No data..." mechanism and the node will appear disabled (non-clickable) and with custom (and/or localizable) message, so this might be more convenient to your clients.
Hope this helps.