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

Default root node

1 Answer 66 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 16 Apr 2013, 03:40 PM
Hello

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.

Root
|-child1
|-child2
|-child3
   |-child3a
   |-child3b
|-child4
|-child5
|-child6

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

here is the code

            SqlConnection conn = new SqlConnection(Global.SQLConnectionString);
            conn.Open();

            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);
            try
            {
                SqlDataReader Dr = Cmd.ExecuteReader();

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

                RadTreeView1.DataSource = Dr;
                RadTreeView1.DataBind();
            }

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


Thanks,

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 17 Apr 2013, 10:38 AM
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.

Regards,
Kate
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
TreeView
Asked by
Brian
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or