Get SelectedItems for the treelist with multiple pages

4 posts, 0 answers
  1. Uday
    Uday avatar
    3 posts
    Member since:
    Feb 2011

    Posted 23 Feb 2011 Link to this post

    I have treelist, which have multiple pages.
    User can select some items on first page, using pager can move to next page and select some other records.

    On save, I am trying to read the Treelist's Selected Items, property, its giving only records selected on the current page and not from the last page.

    Is it by design or do I need to configure some properties to achieve this ?

    While moving between pages, selection is preserved.
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 25 Feb 2011 Link to this post

    Hello Uday,

    This is by design. At any point in RadTreeList, you have access to the visible data items only. Items in other pages, and children that are not visible are not available. Selection is preserved, because we persist the selected indexes between pages and rebinds, but data items are created for the visible records only.

    Veli
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Keith
    Keith avatar
    3 posts
    Member since:
    Jan 2011

    Posted 14 Apr 2011 Link to this post

    Veli,
    Is there a way for me to access the selected indexes you mentioned?

    I need to find out if any children are selected when the parent is collapsed. If this is absolutely not possible, is there a way for me to prevent collapsing a parent node when children are selected?
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 15 Apr 2011 Link to this post

    Selected indexes are not exposed in the public API. You can, however implement a method that will return the number of selected child items for a specified TreeListDataItem. You can then use this method to prevent collapsing if any child item is selected:

    protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
    {
        if (e.CommandName == RadTreeList.ExpandCollapseCommandName)
        {
            TreeListDataItem dataItem = (TreeListDataItem)e.Item;
            if (GetSelectedChildrenCount(dataItem) > 0)
            {
                e.Canceled = true;
            }
        }
    }
     
    protected int GetSelectedChildrenCount(TreeListDataItem dataItem)
    {
        int selectedCount = 0;
        bool beginTrack = false;
     
        foreach (TreeListDataItem item in RadTreeList1.Items)
        {
            //if current item is at the same hierarchy level
            if (item.HierarchyIndex.NestedLevel == dataItem.HierarchyIndex.NestedLevel)
            {              
                if (item == dataItem)
                {
                    //track items from the current item onwards
                    beginTrack = true;
                }
                else if (item.HierarchyIndex.LevelIndex > dataItem.HierarchyIndex.LevelIndex)
                {
                    //the current item is the next item in the same hierarchy level as dataItem
                    //so, we have gone through any existing child items of dataItem
                    break;
                }
            }
            else if (item.HierarchyIndex.NestedLevel > dataItem.HierarchyIndex.NestedLevel)
            {               
                if (beginTrack)
                {
                    //this will execute for child items of the specified dataItem only
                    if (item.Selected)
                    {
                        selectedCount++;
                    }
                }
            }
        }
     
        return selectedCount;
    }

    GetSelectedChildrenCount() in the above code sample retrieves the number of selected items for a specified data item.

    Veli
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top