I have tried using Treeview in my Sanboxsolution webpart but the problem is that in a web page it is not loading properly. And when i click on node it gives me javascript error. For these two errors i have attached screenshots with this question for the reference.Have a look at it.

And in my aspx view i have written following code

<asp:TreeView runat="server" ID="trvComDept" ShowLines="True" ShowExpandCollapse="true" EnableClientScript="true" ImageSet="Simple">
    <asp:TreeNode Text="Parent 1" Value="1">
        <asp:TreeNode Text="Child 1" Value="2"></asp:TreeNode>
        <asp:TreeNode Text="Child 2" Value="3"></asp:TreeNode>

Webpage View enter image description here

JS Error when i click on node enter image description here

Updated Code Is As Below

Aspx Code :-

<asp:TreeView runat="server" ID="trvComDept" ShowLines="True" ShowExpandCollapse="true" EnableClientScript="true" ImageSet="Simple">    

C# Code :

List<string> Roots = new List<string>();
        List<string> Childs = new List<string>();

        for (int i = 0; i < 5; i++)
            Roots.Add("Root" + i.ToString());
            Childs.Add("Child" + i.ToString());

        foreach (string r in Roots)
            TreeNode root = new TreeNode();
            root.Text = r;

            foreach (string c in Childs)
                TreeNode child = new TreeNode();
                child.Text = c;

  • Does this work WITHOUT the C# code? If so, I would get rid of the Nodes section in your aspx markup, and see if the C# then again works. – James Love Nov 22 '12 at 19:18
  • I have to bind the Treeview from the SPList so i must need c# code – Stark Nov 23 '12 at 5:42
  • Understood, but you need to rule out the fact that the code is causing the issue. If the issue persists without C# code, then your code isn't the problem and the problem lies with the ASP.NET markup. I do think though, that you don't need the Nodes section in the markup if you're adding nodes using C#. – James Love Nov 23 '12 at 9:19

When you create a asp tree view in sharepoint you need to create a datasource for it. That's why you are getting the _Data error. I took a look on google for a good guide for you here:

How to use a asp tree view with SharePoint

  • but this is just a demo my true intention is to bind it from SPList and that also i've tried but the result was same – Stark Nov 22 '12 at 9:50
  • Well the error is that you haven't set your data source for the tree. Basically the points in step 2 are missing from your code, without the datasource it won't work I'm afraid. – Hugh Wood Nov 22 '12 at 10:26
  • but in farm solution it is working perfectly without data source....do i compulsory have to give DataSourceId in design view????....and please note that i m using it in sandbox solution – Stark Nov 22 '12 at 12:42
  • System.Web.UI is fine, in SharePoint online, so it should be fully supported. I'm just wondering could you paste a more complete version of your code, I feel there is something I am not seeing so I probably misunderstanding the situation. – Hugh Wood Nov 22 '12 at 13:13
  • i have add my new code in this question. So please have a look at it.... – Stark Nov 22 '12 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.