i have multilevel marketing software data in which a person may join many other person and again joind person will do the same.
i have tried these code
protected void load_data()
{
strQuery = "select * from redjoining where id=995";
cmd = new SqlCommand(strQuery);
dt = dbcon.GetData(cmd);
string cat_code = dt.Rows[0]["id"].ToString();
string cat_name = dt.Rows[0]["userName"].ToString();
TreeNode parent = new TreeNode();
parent.Value = cat_code;
parent.Text = cat_name;
TreeView1.Nodes.Add(parent);
add_childs(parent, cat_code);
}
now to add child node i use this code but it add only top single record only.
protected void add_childs(TreeNode tn, string category_code)
{
strQuery = "select * from redjoining where sponserid=@category_code";
cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@category_code", category_code);
dt = dbcon.GetData(cmd);
for (int i = 0; i < dt.Rows.Count; i++)
{
string cat_code = dt.Rows[0]["id"].ToString();
string cat_name = dt.Rows[0]["userName"].ToString();
TreeNode child = new TreeNode();
child.Value = cat_code;
child.Text = cat_name;
tn.ChildNodes.Add(child);
add_childs(child, cat_code); //calling the same function
}
}