Telerik Treelist NeedDataSource doesn't load data

18 posts, 1 answers
  1. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 19 Dec 2011 Link to this post

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Dec 2011 Link to this post

    Hello,

    Take a look into the following documentation
    Simple vs Advanced Binding

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 20 Dec 2011 Link to this post

    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
  5. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 20 Dec 2011 Link to this post

    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
  6. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 20 Dec 2011 Link to this post

    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.
  7. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 20 Dec 2011 Link to this post

    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
  8. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 20 Dec 2011 Link to this post

    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.
  9. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 22 Dec 2011 Link to this post

    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
  10. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 22 Dec 2011 Link to this post

    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
  11. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 22 Dec 2011 Link to this post

    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
  12. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 22 Dec 2011 Link to this post

    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..
  13. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 23 Dec 2011 Link to this post

    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
  14. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 23 Dec 2011 Link to this post

    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
  15. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 26 Dec 2011 Link to this post

    No answer to my question? I really can't use Telerik RadTreelist control this time.

  16. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 27 Dec 2011 Link to this post

    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
  17. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 27 Dec 2011 Link to this post

    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.
  18. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 29 Dec 2011 Link to this post

    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
  19. Mehmet Şerif
    Mehmet Şerif avatar
    12 posts
    Member since:
    Nov 2011

    Posted 29 Dec 2011 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017