Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
Cancel postback for WebTree
posted

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.

Private Sub PopulateNode(ByVal node As Infragistics.WebUI.UltraWebNavigator.Node)

Dim userInfoID As Long = CType(node.DataPath, Long)

Dim dtReports As DataTable = Me.GetDirectReports(userInfoID)Dim newNode As Infragistics.WebUI.UltraWebNavigator.Node

Node.Nodes.Clear()

If dtReports.Rows.Count > 0 Then

For Each row As DataRow In dtReports.RowsnewNode = createTreeNode(row.Item("LastFirstName"), row.Item("UserInformationID"), Not (GlobalFnc.IsNull(row.Item("EmployeeID")) And Not CType(row.Item("ActiveSuit"), Boolean)))

node.Nodes.Add(newNode)

Next

node.Expanded = True

Else

node.Expanded = False

node.ShowExpand = False

End If

End Sub

Private Sub tvwHierarchy_DemandLoad(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs) Handles tvwHierarchy.DemandLoad

Me.PopulateNode(e.Node)

End Sub

Parents
  • 28464
    posted

    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.

Reply Children
No Data