1

MLM data sample

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
        }
    }
4

1 回答 1

0

您在树视图中添加子记录的方法存在问题,请检查以下代码

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[i]["id"].ToString();
            string cat_name = dt.Rows[i]["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
        }
    }

在您的代码中,您总是使用dt.Rows[0]["id"].ToString()

使用 i 作为您的 dt 有多个记录,并且您正在迭代 for 循环。

希望这会有所帮助。

于 2019-06-10T09:00:26.943 回答