Sorting rad TreeView after databinding

3 posts, 0 answers
  1. Johan
    Johan avatar
    617 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2007 Link to this post


    r.a.d.controls version rad TreeView 6.x +
    .NET version

    1.x and 2.x     
    Visual Studio version

    VS 2005
    programming language

    browser support

    all browsers supported by r.a.d.controls

    Demonstrates how to sort the treeview after databinding. Currently only swaps the Text of the nodes, you may need to modify the code to swap Value, Category, etc (all the properties you need).
  2. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 01 Sep 2009 Link to this post


    I just downloaded the project and modified the data Default.aspx like this:
       <radT:RadTreeView ID="RadTreeView1" runat="server"
             <radT:RadTreeNode runat="server" Text="item c"
                   <radT:RadTreeNode runat="server" Text="c2"
                   <radT:RadTreeNode runat="server" Text="c1"
                         <radT:RadTreeNode runat="server" Text="c1_2"
                         <radT:RadTreeNode runat="server" Text="c1_3"
                         <radT:RadTreeNode runat="server" Text="c1_1"
             <radT:RadTreeNode runat="server" Text="item a"
                   <radT:RadTreeNode runat="server" Text="a1"
                         <radT:RadTreeNode runat="server" Text="a1_1"
             <radT:RadTreeNode runat="server" Text="item b"
                   <radT:RadTreeNode runat="server" Text="b2"
                   <radT:RadTreeNode runat="server" Text="b1"
                   <radT:RadTreeNode runat="server" Text="b3"
                         <radT:RadTreeNode runat="server" Text="b3_2"
                         <radT:RadTreeNode runat="server" Text="b3_1"

    I was expecting to see the nodes starting with 'a' under 'item a' and the nodes starting with 'b' under 'item b'. But what I get is this:
    - item a 
    |   |_c1 
    |   |_c2 
    |     |_c1_1 
    |     |_c1_2 
    |     |_c1_3      
    - item b 
    |   |_a1 
    |     |_a1_1 
    - item c 

    Is the sorting not working correctly or am I misunderstanding something?

    Thanks for helping,

  3. avatar
    7 posts
    Member since:
    Sep 2005

    Posted 19 May 2011 Link to this post

    It's better with LINQ

    Create your nodes to a list collection List<radTreeNode>

    Sort the List, then add to the nodes using the AddRange method.

    Here's the sort in LINQ.




    protected List<RadTreeNode> SortNodeCollection(List<RadTreeNode> nodes)






    List<RadTreeNode> returnCollection = new List<RadTreeNode>();




    var q = from node in nodes




    orderby node.Text ascending








    select node;



    returnCollection = q.ToList<





    return returnCollection;




Back to Top