Default root node

2 posts, 0 answers
  1. Brian
    Brian avatar
    1 posts
    Member since:
    Sep 2011

    Posted 16 Apr 2013 Link to this post


    I am working on radtreeview control. I am new to telerik controls
    I am having a problem, see if you guys can help me on it.

    I am trying to set default static root for the categories, I have database table name called categories, has iID and iParent columns that make relation of parent and child. 

    I want to achieve treeview like this.


    but i am gettign all child1 to child 6 at root line including root.

    here is the code

                SqlConnection conn = new SqlConnection(Global.SQLConnectionString);

                string sqlString;
                //sqlString = "SELECT * FROM [MediaLibraryCategories]";
                sqlString = "Select iID,Title,iParent From Categories Union All Select '0','root', -1 Order By Sort";

                SqlCommand Cmd = new SqlCommand(sqlString, conn);
                    SqlDataReader Dr = Cmd.ExecuteReader();

                    RadTreeView1.DataFieldID = "iID";
                    RadTreeView1.DataFieldParentID = "iParent";
                    RadTreeView1.DataTextField = "Title";
                    RadTreeView1.DataValueField = "iID";

                    RadTreeView1.DataSource = Dr;

    with Union All, 0  is the iID, root is the title, and -1 is the iParent
    other data are like this..

    iID, Title, iParent
    1    child1  0
    2    child2  0
    3    child3  0
    4    child4  0

    5    child5  0

    6    child6  0

    7   child3a 3
    8   child3b 3

    Union All

    0 Root -1

  2. Kate
    Kate avatar
    1898 posts

    Posted 17 Apr 2013 Link to this post

    Hello Brian,

    To get the RadTreeView bound to a hierarchical data source you will need to have a hierarchical data structure on the first place. In case you use an SQL data source in the data table you will need to establish the parent->child relationship and then set the corresponding fields (columns) to the DataFieldID 9that would be the ID column described in the below article) and the DataFieldParentID (ParentID column) properties. Here you can find more detailed explanation on how to bind a RadTreeView control to a hierarchical data source.

    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