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

No records to display.

4 Answers 503 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
alexandre
Top achievements
Rank 1
alexandre asked on 01 Jun 2011, 09:01 AM
Hello,

As I have to test some RadControls components for my company, I'm currently working on the TreeList control. Even if I only try to do basic stuff (populate the control with a database query) It doesn't work and I just can't figure out why !
My previous investigation lead me to think that issue is related to DataKeyNames and ParentDataKeyNames properties but I'm not sure.
So instead of talking about my work, I'll let you get an code snippet so as you can take a look at it :

<telerik:RadTreeList ID="RadTreeList1" runat="server"
        AllowMultiItemEdit="False" AllowPaging="True" Culture="(Default)"
        DataKeyNames="SousThemeID" ParentDataKeyNames="SousThemThemeID" AutoGenerateColumns="True" DataSourceID="SqlDataSource1" IsItemInserted="False">
 
<ValidationSettings CommandsToValidate="PerformInsert,Update"></ValidationSettings>
        <Columns>
            <telerik:TreeListBoundColumn UniqueName="column"></telerik:TreeListBoundColumn>
        </Columns>
<EditFormSettings EditFormType="AutoGenerated"></EditFormSettings>
</telerik:RadTreeList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ContenuConnectionString %>"
        SelectCommand="SELECT [SousThemeID], [SousThemLibelle], [SousThemThemeID] FROM [SousTheme]">
    </asp:SqlDataSource>


Here's a little explanation concerning my query :

1. it works well so the problem doesn't come from here
2. SousThemeID : Integer, SousThemLibelle : String, SousThemThemeID : integer
3. SousTheme (which means under-theme or theme below) is related to Theme (Theme.ThemeID = SousTheme.SousThemThemeID).

Example  :

[ 1 ] [ "test" ] [ 1 ]
[ 2 ] [ "whatever you want" ] [ 1 ]
[ 3 ] [ "Computer" ] [ 1 ]
[ 4 ] [ "Economy" ] [ 2 ]
[ 5 ] [ "Finance" ] [ 2 ]


If you have any idea on what's going wrong in my code, please let me know.
Thanks in advance.


Alexandre.

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 01 Jun 2011, 09:50 AM
Hi alexandre,

The reason you cannot bind RadTreeList to this sample data, is because your root items need to have null or default values for their parent keys. In your sample data:

[ 1 ] [ "test" ] [ 1 ]
[ 2 ] [ "whatever you want" ] [ 1 ]
[ 3 ] [ "Computer" ] [ 1 ]
[ 4 ] [ "Economy" ] [ 2 ]
[ 5 ] [ "Finance" ] [ 2 ]

your root item is the first one, but it has a parent key value equal to its primary key value. RadTreeList expects root items to either have a NULL as their parent keys, or the default value for the specified data type (0 for numeric). If you change the SousThemThemeID value of your first item to 0, you will have this tree show up properly in RadTreeList.

Greetings,
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.

0
alexandre
Top achievements
Rank 1
answered on 01 Jun 2011, 10:41 AM
Hi Veli,

Thank you for your quick response.
However, even though I now understand what was wrong, I'm still in troubles.
I'm sorry I didn't express myself properly.

My example should rather be like this :

[ 101 ] [ "test" ] [ 1 ]
[ 102 ] [ "whatever you want" ] [ 1 ]
[ 103 ] [ "Computer" ] [ 1 ]
[ 201 ] [ "Economy" ] [ 2 ]
[ 202 ] [ "Finance" ] [ 2 ]

So instead of querying for "SousTheme" I tried "Theme". There are basically 7 themes :
[ID] [Description]

I do understand it's not possible to display them as they aren't related to any root item.
My question is how can I create a root item then bind it to my query results ? Because I cannot create/add any fields in
the database as it is currently used by many applications.

Edit: I just found this :
http://www.telerik.com/help/aspnet-ajax/media/treelist_understanding-structure.png
and it looks like it is possible to display several root items, am I wrong ?

Thanks in adance,

Regards,

Alexandre.
0
Accepted
Veli
Telerik team
answered on 01 Jun 2011, 11:33 AM
Hello alexandre,

RadTreeList can display an arbitrary number of root items. It is not restricted to a single root item. What is important, in this case, is that root items should have either NULL or 0 in their parent key fields. RadTreeList identifies root items by their default or omitted parent key values.

As for your question on creating items, note that RadTreeList supports data source binding only. Like any other databound control in ASP.NET, you need to specify a data source to bind RadTreeList to.

What you can do is use RadTreeList's NeedDataSource event to bind the control programmatically. As the SqlDataSource control directly fetches the data from the database, and you cannot use the data in this form, you need to modify the retrieved data and pass it forward to RadTreeList. The NeedDataSource event is provided exactly for that reason. Inside the event handler, you can query your database, iterate over your data and build your hierarchical tree. Root items should have 0 or null in their parent key fields, while child items should specify the exact data key value of their parents.

Greetings,
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.

0
alexandre
Top achievements
Rank 1
answered on 01 Jun 2011, 04:46 PM
Hi Veli,

Thanks again for your help : It works perfectly now !

Regards,


Alexandre.
Tags
TreeList
Asked by
alexandre
Top achievements
Rank 1
Answers by
Veli
Telerik team
alexandre
Top achievements
Rank 1
Share this question
or