Moksha
Moksha

Reputation: 1030

Populate asp.net treeview Node on selected

I am populating asp.net treeview with database table. I am trying to populate a node when its click from database table, I tried what I can google but I am not getting it. please help

  • Root
    • Fruits
    • Meat
    • Beverage - if someone click Beverage I want to connect to database and get a list of all and display them under Beverage

To

  • Root
    • Fruits
    • Meat
    • Beverage
      • Alcoholic beverages
      • Non-alcoholic beverages

Thanks Regards

Upvotes: 0

Views: 2230

Answers (1)

Mark Kadlec
Mark Kadlec

Reputation: 8450

You can actually take advantage of native treenode functionality to write your Ajax type behaviour.

There are two TreeNode node properties you can take advantage of:

PopulateOnDemand: Set this property of each TreeNode to the value true for that you want to have a lazy loading of it's child-nodes.

OnTreeNodePopulate: This is a property of the TreeView in which you have to define the method that is called when expanding a TreeNode.

Take advantage of these and put your DB call (or cached value lookup) in the method defined by OnTreeNodePopulate.

Once done, it should work really great (and efficient).

Here is a link to the MS documentation relating to it (pretty good example)

Upvotes: 1

Related Questions