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

Check Parent has Child

5 Answers 114 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 01 Feb 2012, 03:06 PM
Hi,

I need to known how can I check if parent node has a child.

Thanks,

Allan.

5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 01 Feb 2012, 04:16 PM
Hello Allan,

You can check using the following code, assuming "item" is the current TreeListDataItem object you are checking:
if(item.ChildItems.Count>0)
{
    //code here
}


All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Allan
Top achievements
Rank 1
answered on 01 Feb 2012, 06:34 PM
Thanks Tsvetina, for ur fast reply!

But I still can't check those child.

How can I check it using the code above?

For Each TreeListItems As TreeListDataItem In RadTreeList1.Items
 
Next





0
Princy
Top achievements
Rank 2
answered on 02 Feb 2012, 05:42 AM
Hello,

Try the following.
VB:
For Each item As TreeListDataItem In RadTreeList1.Items
    If item.ChildItems.Count > 0 Then
                 //your code
    End If
Next

Thanks,
Princy.
0
Allan
Top achievements
Rank 1
answered on 02 Feb 2012, 12:36 PM
Thanks Princy,

I used your code, but still can't count the childitems.

It's show the error message : ChildItems is not a member of Telerik.Web.UI.TreelistDataItem

Can you help me?


Thanks,
Allan.

0
Tsvetina
Telerik team
answered on 02 Feb 2012, 02:30 PM
Hi Allan,

It seems that you are using an older version of RadControls which does not expose this property yet. It would be best if you could upgrade to the latest version.
If this is not possible, you would need to loop through all visible TreeListDataItem objects and collect those which have a parent id corresponding to the id of the current item. Something like:
Protected Sub RadTreeList1_PreRender(sender As Object, e As EventArgs)
    Dim parent As TreeListDataItem = RadTreeList1.Items(0) //instead of this line, access the item you need to find the children of
    Dim id As String = parent.GetDataKeyValue("ID").ToString()
    Dim children As New TreeListDataItemCollection()
    For Each item As TreeListDataItem In RadTreeList1.Items
        If item.GetParentDataKeyValue("ParentID") IsNot Nothing AndAlso item.GetParentDataKeyValue("ParentID").ToString() = id Then
            children.Add(item)
        End If
    Next
'use children collection
End Sub


Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeList
Asked by
Allan
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Allan
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or