Solved

help with treeview populate on demand

Posted on 2007-03-17
1
2,917 Views
Last Modified: 2010-05-18
I have an issue where I am tryiong to populate a treeview programmaticaly and I would like to populate all of the child nodes "ondemand" using the populateondemand

however if I set a node to populateondemand = true;

I get the error

"PopulateOnDemand can't be set to true on a node that already has children."  

It seems pretty obvious to me that  dont understand the correct way to impliment this.

Could someone take a look at my code and suggest o me a way to have the child objects starting from the root level only populate when someones expands the node?

this is my code that fills the Treeview.

protected void Page_Load(object sender, EventArgs e)
    {
   

                     tvAreaTableAdapter tvAreaAdapt = new tvAreaTableAdapter();


        TreeviewDS.tvAreaDataTable areaDT = tvAreaAdapt.GetArea();
   
     
       
       
       
       foreach (DataRow r1 in areaDT)
       {
         
           long areaID = Convert.ToInt64(r1["AreaID"]);
           TreeNode anode = new TreeNode();        
           anode.Text = "Area " + r1["AreaName"].ToString();
           anode.Value = r1["AreaID"].ToString();

           anode.PopulateOnDemand = true;
     
           TreeView1.Nodes.Add(anode);
           
         
           tvRowTableAdapter tvRowAdapt = new tvRowTableAdapter();
           TreeviewDS.tvRowDataTable rowDT = tvRowAdapt.GetRows(areaID);

           foreach (DataRow r2 in rowDT)
           {
               long rowID = Convert.ToInt64(r2["RowID"]);
               TreeNode rnode = new TreeNode();
               rnode.Text = "Row " + r2["RowNumber"].ToString();
               rnode.Value = r2["RowID"].ToString();
              rnode.PopulateOnDemand = true;
             
               anode.ChildNodes.Add(rnode);

               tvVineTableAdapter tvVineAdapt = new tvVineTableAdapter();
               TreeviewDS.tvVineDataTable vineDT = tvVineAdapt.GetVines(rowID);

               foreach (DataRow r3 in vineDT)
               {
                   TreeNode vnode = new TreeNode();
                   vnode.Text = "Vine " + r3["Vine"].ToString();
                   vnode.Value = r3["VineID"].ToString();
                   rnode.ChildNodes.Add(vnode);
               }
           }

        }


    }      
0
Comment
Question by:Prysson
1 Comment
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18743133
You musn't fill the full tree at the begin and you need an event handler for PopulateNode
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode.populateondemand.aspx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question