Check Parent has Child

6 posts, 0 answers
  1. Allan
    Allan avatar
    6 posts
    Member since:
    Oct 2011

    Posted 01 Feb 2012 Link to this post

    Hi,

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

    Thanks,

    Allan.
  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 01 Feb 2012 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Allan
    Allan avatar
    6 posts
    Member since:
    Oct 2011

    Posted 01 Feb 2012 Link to this post

    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





  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Feb 2012 Link to this post

    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.
  6. Allan
    Allan avatar
    6 posts
    Member since:
    Oct 2011

    Posted 02 Feb 2012 Link to this post

    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.

  7. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 02 Feb 2012 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017