开发者

dynamically generating the nodes in treeview control and displaying the results on selecting the node in asp .net

开发者 https://www.devze.com 2023-02-20 18:03 出处:网络
I am using a treeview control and jus开发者_如何学Got want to add nodes dynamically.On selecting a node the

I am using a treeview control and jus开发者_如何学Got want to add nodes dynamically.On selecting a node the results based on that node must be shown below.

Thanks in advance


This is how you set the TreeView to dynamically add the child nodes using Ajax.

var tree = new TreeView()
{
  PopulateNodesFromClient = true,
  EnableClientScript = true
};

tree.TreeNodePopulate += (s, e) => 
{
  var childItems = CallTheDB(e.Node.Value); //Get the children for the parent node
  foreach(var item in childItems)
  {
     e.Node.ChildNodes.Add(new TreeNode()
     {
       PopulateOnDemand = true,
       Text = item.Text,
       Value = item.Key,
       SelectAction = TreeNodeSelectAction.Expand
     });
  }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消