Skip Navigation Links.

ASP.NET 2.0 Dynamic Tree View

The following shows an example of dynamically building a TreeView:

     Skip Navigation Links.

The code is simply added at the Page Load, and the TreeView nodes are deleted, and then added. In this case the links are generated from an ArrayList (links):

protected void Page_Load(object sender, EventArgs e) { 
  if (!IsPostBack)              
  { 
   foreach (TreeNode n in TreeView1.Nodes) 
   { // get rid of the current nodes          
       nodes TreeView1.Nodes.Remove(n); 
   } 

   // Create some nodes from an ArrayList
   ArrayList links = new ArrayList();              
   links.Add("aspx01.aspx"); links.Add("aspx02.aspx"); 
   links.Add("aspx03.aspx"); links.Add("aspx04.aspx"); 

   // Populate the nodes
   foreach (string s in links) 
   { 
     TreeNode tn = new TreeNode(); 
     tn.Text = s; 
     tn.NavigateUrl = s; 
     TreeView1.Nodes.Add(tn);             
    } 
  } 
}