Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to load data from 1 table in my database to a tree view using C# language ,,

and this table has a recursive relation between 2 columns in it...
Posted
Comments
Sergey Alexandrovich Kryukov 22-Dec-11 19:57pm    
What have you done so far?
--SA

1 solution

Letz assume two column names are col1 and col2. Code sample PageLoad() is:

C#
foreach (DataRow row in myTable.Rows)
{
    TreeNode node = new TreeNode(dr["col1"], dr["col2"]);
    node.PopulateOnDemand = true;

     TreeView1.Nodes.Add(node);
 }
 ///
 protected void PopulateNode(Object sender, TreeNodeEventArgs e)
 {
     string col1Id = e.Node.Value;
     foreach (DataRow row in myTable.Rows)
     {
         TreeNode node = new TreeNode(dr["col1"], dr["col2"]);
         node.PopulateOnDemand = true;

         e.Node.ChildNodes.Add(node);
     }

 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900