Creating the Form

To demonstrate how to populate a tree view control with links, we will need to create a simple web form. To begin, create a new ASP.NET Empty Web Site and:

  1. Right click the project in your solution explorer.
  2. Select add new item…
  3. Select a web form.
  4. Name it ‘Default.aspx’.
  5. Click add.
  6. Open Default.aspx up to design mode.
  7. Drag and drop a treeview onto the web form.
  8. Change the ID property to ‘Treeview1′.
  9. Set the AutoGenerateDataBindings property to ‘False’.
  10. Add the following nodes to the treeview:

    Once we have our tree view setup we need to add some code that will populate it with some links. To do this, open Default.aspx up to design mode and:

    1. Select the treeview.
    2. Click the Events icon in the Properties window.
    3. Double click the TreeNodePopulate event.
    4. Add the following code to that event method:


    To test this out load up the web site. Ensure that the tree view has some links in it and expands when you click it.

    Download Source Files