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

Telerik Treelist NeedDataSource doesn't load data

18 Answers 266 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Mehmet Şerif
Top achievements
Rank 1
Mehmet Şerif asked on 19 Dec 2011, 08:08 PM

I'm trying to load treelist, everything works well but i always see "No Records To Display".

Here is the control:

<telerik:RadTreeList ID="trlProductGroups" runat="server" AllowPaging="true" PageSize="5"
       
DataKeyNames="ID" ParentDataKeyNames="PARENT_ID" AutoGenerateColumns="false"
       
OnInsertCommand="trlProductGroups_InsertCommand" OnNeedDataSource="trlProductGroups_NeedDataSource"
       
OnUpdateCommand="trlProductGroups_UpdateCommand" OnDeleteCommand="trlProductGroups_DeleteCommand">
       
<Columns>
           
<telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
               
HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" />
           
<telerik:TreeListEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton">
               
<ItemStyle CssClass="MyImageButton" />
           
</telerik:TreeListEditCommandColumn>
           
<telerik:TreeListButtonColumn UniqueName="DeleteCommandColumn" Text="Delete" CommandName="Delete"
               
ButtonType="ImageButton" />
           
<telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Grup ID"
               
ReadOnly="true" />
           
<%-- <telerik:TreeListTemplateColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı">
               
<EditItemTemplate>
                   
<asp:TextBox ID="txtGroupName" runat="server"></asp:TextBox>
               
</EditItemTemplate>
            </
telerik:TreeListTemplateColumn>--%>
           
<telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı" />
           
<telerik:TreeListBoundColumn DataField="PARENT_ID" UniqueName="PARENT_ID" HeaderText="Ana Grup ID"
               
ReadOnly="true" />
       
</Columns>
   
</telerik:RadTreeList>


And here is the NeedDataSource Code:

 protected void trlProductGroups_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
       
{

           
WebAppTest.Objects.ProductGroups pGroups = new WebAppTest.Objects.ProductGroups();
           
DataTable dt = pGroups.SelectData(null, string.Empty);
            trlProductGroups
.DataSource = dt;
       
}

I can see the data in DataTable, but treelist wont load data. Is there any mistake i make?

Thanks

18 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Dec 2011, 05:26 AM
Hello,

Take a look into the following documentation
Simple vs Advanced Binding

Thanks,
Princy.
0
Tsvetina
Telerik team
answered on 20 Dec 2011, 12:33 PM
Hello Mehmet,

Can you confirm that the values inside your parent key field and the key field are of the same data-type? Also, do you have items which have as a parent key value the default value for its datatype (null for int, "" for string, etc.)?
These are the two main rules that you need to have in mind when trying to bind data to RadTreeList. A more detailed description on them is available here:
Understanding RadTreeList Structure

Kind regards,
Tsvetina
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
0
Tsvetina
Telerik team
answered on 20 Dec 2011, 12:33 PM
Hello Mehmet,

Can you confirm that the values inside your parent key field and the key field are of the same data-type? Also, do you have items which have as a parent key value the default value for its datatype (null for int, "" for string, etc.)?
These are the two main rules that you need to have in mind when trying to bind data to RadTreeList. A more detailed description on them is available here:
Understanding RadTreeList Structure

Kind regards,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 20 Dec 2011, 12:53 PM
Hello,

Parent key field and the key field are of the same data-type (long). But i don't give them a default value. I also tried Simple Data Binding but nothing changed. Still got the same result. My structure is like this :

ID long
GROUP_NAME string
PARENT_ID long

so i think there is nothing inadaptable for RadTreeList.
0
Tsvetina
Telerik team
answered on 20 Dec 2011, 01:23 PM
Hello Mehmet,

What I mean is that you need to have records in the datasource having as parent key value the default value of the datatype they are.
So, if the datatype is long, you need to have records with PARENT_ID=0.
If it is nullable long, you need to have records with PARENT_ID=null.

Otherwise, no root items can be resolved and there is no way for the treelist to build its hierarchy.

Best wishes,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 20 Dec 2011, 01:41 PM
Hello,

Well in datatable i can see that parent key values are 0 for the root items.

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><br><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"><br></asp:Content><br><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><br>    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /><br>    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" /><br>    <telerik:RadTreeList ID="trlProductGroups" runat="server" AllowPaging="true" PageSize="5"<br>        DataKeyNames="ID" ParentDataKeyNames="PARENT_ID" AutoGenerateColumns="false"<br>        OnInsertCommand="trlProductGroups_InsertCommand" OnNeedDataSource="trlProductGroups_NeedDataSource"<br>        OnUpdateCommand="trlProductGroups_UpdateCommand" OnDeleteCommand="trlProductGroups_DeleteCommand"><br>        <Columns><br>            <telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"<br>                HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" /><br>                <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:TreeListBoundColumn><br>            <telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı" /><br>            <telerik:TreeListBoundColumn DataField="PARENT_ID" UniqueName="PARENT_ID" HeaderText="Ana Grup ID"<br>                ReadOnly="true" /><br>        </Columns><br>    </telerik:RadTreeList><br>    <telerik:RadTreeList ID="RadTreeList1" runat="server" OnNeedDataSource="RadTreeList1_NeedDataSource"<br>        ParentDataKeyNames="PARENT_ID" DataKeyNames="ID" AllowPaging="true" PageSize="5"<br>        AutoGenerateColumns="false" AllowSorting="true"><br>        <Columns><br>            <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Category ID" /><br>            <br>            <telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME"<br>                HeaderText="Ad"><br>                <ItemStyle HorizontalAlign="Right" /><br>            </telerik:TreeListBoundColumn><br>            <telerik:TreeListBoundColumn DataField="ParentID" UniqueName="ParentID" HeaderText="Parent Category ID" /><br>        </Columns><br>    </telerik:RadTreeList><br></asp:Content>


protected void Page_Load(object sender, EventArgs e)<br>        {<br>            if (!Page.IsPostBack)<br>            {<br>                <br>            }<br>        }<br><br>        <br><br>        protected void trlProductGroups_InsertCommand(object sender, TreeListCommandEventArgs e)<br>        {<br>            Hashtable table = new Hashtable();<br>            <br>            TreeListEditableItem item = (TreeListEditableItem)e.Item;<br>            item.ExtractValues(table);<br>            <br>            WebAppTest.Objects.Product_Groups pGroups = new WebAppTest.Objects.Product_Groups();<br>            pGroups.GROUP_NAME = table["GROUP_NAME"].ToString();<br>            if (!table.ContainsKey("PARENT_ID"))<br>            {<br>                table["PARENT_ID"] = DBNull.Value;<br>            }<br>            else<br>            {<br>                pGroups.PARENT_ID = int.Parse(table["PARENT_ID"].ToString());<br>            }<br>            <br>            pGroups.Insert();<br>            <br>        }<br><br>        protected void trlProductGroups_UpdateCommand(object sender, TreeListCommandEventArgs e)<br>        {<br><br>            //TreeListEditableItem item = (TreeListEditableItem)e.Item;<br>            //TextBox txtGroupName = (TextBox)item.FindControl("txtGroupName");<br><br>            //WebAppTest.Objects.ProductGroups pGroups = new WebAppTest.Objects.ProductGroups();<br>            //pGroups.GROUP_NAME = txtGroupName.Text;<br>            //pGroups.Insert();<br>        }<br><br>        protected void trlProductGroups_DeleteCommand(object sender, TreeListCommandEventArgs e)<br>        {<br><br>            //TreeListEditableItem item = (TreeListEditableItem)e.Item;<br>            //TextBox txtGroupName = (TextBox)item.FindControl("txtGroupName");<br><br>            //WebAppTest.Objects.ProductGroups pGroups = new WebAppTest.Objects.ProductGroups();<br>            //pGroups.GROUP_NAME = txtGroupName.Text;<br>            //pGroups.Insert();<br>        }<br><br>        protected void trlProductGroups_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)<br>        {<br><br>            WebAppTest.Objects.Product_Groups pGroups = new WebAppTest.Objects.Product_Groups();<br>            DataTable dt = pGroups.SelectData(null, string.Empty);<br>            trlProductGroups.DataSource = dt;<br>            <br>        }

These are the complete files.
0
Tsvetina
Telerik team
answered on 22 Dec 2011, 12:34 PM
Hello Mehmet,

Can you please try pasting the code snippets again (they came out quite messed up) and also paste some sample data from the DataTable which you bind the RadTreeList to. I will use them in a test project and let you know what I find out after debugging it.

Greetings,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 22 Dec 2011, 01:03 PM
Ok here is my radtreelist in a masterpage:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" />
    <telerik:RadTreeList ID="trlProductGroups" runat="server" AllowPaging="true" PageSize="5"
        DataKeyNames="ID" ParentDataKeyNames="PARENT_ID" AutoGenerateColumns="false"
        OnInsertCommand="trlProductGroups_InsertCommand" OnNeedDataSource="trlProductGroups_NeedDataSource"
        OnUpdateCommand="trlProductGroups_UpdateCommand" OnDeleteCommand="trlProductGroups_DeleteCommand">
        <Columns>
            <telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
                HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" />
                <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:TreeListBoundColumn>
            <telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı" />
            <telerik:TreeListBoundColumn DataField="PARENT_ID" UniqueName="PARENT_ID" HeaderText="Ana Grup ID"
                ReadOnly="true" />
        </Columns>
    </telerik:RadTreeList>
  

and here is the cs code:

protected void trlProductGroups_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
        {

            WebAppTest.Objects.Product_Groups pGroups = new WebAppTest.Objects.Product_Groups();
            DataTable dt = pGroups.SelectData(null, string.Empty);
            trlProductGroups.DataSource = dt;
            
        }

So the datatable looks like this
Id         Group_Name      Parent_ID
1           Cephe Grubu     0
2           Zemin Grubu      0
3           Ekoton Klinker    1
4           Sari Tugla           1
5           Ornek Tugla        2

Thanks
0
Tsvetina
Telerik team
answered on 22 Dec 2011, 04:48 PM
Hi Mehmet,

I am attaching the project I built with your code. The treelist binds correctly in it on my side. Can you test it locally and let me know what am I missing out? I only changed the DataField values of the columns (to match those from my datatable) and removed the command events.

Regards,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 22 Dec 2011, 05:21 PM
Your solution is working but when i try it, i still got no records in treelist. My "ID" field is long and in database i make it number(16), can that make a problem when binding the datatable?

Well now i looked at your code and you also made them long. Also the treelist is in Master Page..
0
Tsvetina
Telerik team
answered on 23 Dec 2011, 02:45 PM
Hello Mehmet,

Do you mean that you managed to replicate the issue in my page? Did you make any code changes and if so, what were they?
Also, which version of the controls are you using, does it make a difference if you change the .dlls in my project?
Is the treelist on the master page itself? If so, please make sure that your script manager is also declared there and that its declaration is before the treelist's.

All the best,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 23 Dec 2011, 03:16 PM
Hello,

No i don't mean that, yours is working very well. The version number of my Telerik.Web.UI.dll is : 2011.2.809.35 and treelist is in ContentPlaceHolder but i declared the scriptmanager in ContentPlaceHolder.

Thanks
0
Mehmet Şerif
Top achievements
Rank 1
answered on 26 Dec 2011, 01:44 PM
No answer to my question? I really can't use Telerik RadTreelist control this time.

0
Tsvetina
Telerik team
answered on 27 Dec 2011, 02:47 PM
Hello Mehmet,

The problem is that we still cannot replicate the problem, the modified project using a master page is attached to this message for your review. If you still cannot point out what is different in your scenario, consider opening a formal support thread and sending us a runnable demo demonstrating the problem which you encounter. We will debug the page and let you know what is wrong.

All the best,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 27 Dec 2011, 03:17 PM
Hi,

I copied your code and changed with mine, it worked. Then i added my datatable which populated from a database, it stopped working. In your code field names are like "Id"-"Parent_Id". But in my database the field names are uppercase, can that make a problem because i see the datatable is not empty. I can see that Masterpage is not a problem in my case. I use SQLite as a database, can that make a problem?

Thanks for your helps.
0
Accepted
Tsvetina
Telerik team
answered on 29 Dec 2011, 10:29 AM
Hi Mehmet,

The problem should not be in the underlying database, the important thing is what is available in the DataTable which you then use to bind the grid. Have you, just for the purpose of testing whether the problem is with the treelist control itself, tried to bind another control that supports self-referencing data, like a RadTreeView or a self-referencing RadGrid?
If they do not manage to bind, too, then there is something wrong with the data fields used for key names and parent key names.

All the best,
Tsvetina
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
0
Mehmet Şerif
Top achievements
Rank 1
answered on 29 Dec 2011, 11:29 AM
Ok i found the solution, when i make root parent_ids = null, treelist started working. Treeview helped me to find the problem.

Thanks for the help.
0
Kendo UI user
Top achievements
Rank 1
answered on 31 Dec 2016, 08:11 AM

Hi Mehmet,

Where did you set root? In Data Source?

Thanks,

KU

Tags
TreeList
Asked by
Mehmet Şerif
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tsvetina
Telerik team
Mehmet Şerif
Top achievements
Rank 1
Kendo UI user
Top achievements
Rank 1
Share this question
or