C#创建依赖于孩子的跟踪父母

时间:2015-11-04 14:09:16

标签: c# sql-server listbox parent-child

我正在尝试创建具有多个子项的Parent的轨道,并将主题置于动态ListBox

我有这个ParentActivity表“

tblParentActivity

我希望将依赖于ParentActivity表的曲目放在ListBox中,如下所示:

Tracks in ListBox

到目前为止的代码:

-1

例如ParentActivityID = 1;

selectBrotherActivity是查询以获取其父子的另一个孩子

它给了我这样的发行:

| 1 | 2 3 | 4 5 | 7 | 9 | 10 | 7 | 9 | 10 | 6 | 8 | 9 | 10 |

哪个||表示ListBox

1 个答案:

答案 0 :(得分:0)

好的,感谢我找到的每个人:

protected void btnCreateTrack_Click(object sender, EventArgs e)

{

  ListBox lstBoxParent = new ListBox();
  lstBoxParent.ID = "lstTrack1";
  lstBoxParent.Width = 200;
  lstBoxParent.Height = 200;
  pnlTrack.Controls.Add(lstBoxParent);

  TrackingActivity(1, lstBoxParent );

}



private void TrackingActivity(long ParentActivityID, ListBox lstBoxParent)
{

    chk:

    DataTable dtActiveChild  = objWFAI.SelectActivityChild(ParentActivityID);
    string ActivityName = objWFA.CurrentActivityName(ParentActivityID);


    lstBoxParent.Items.Add(new ListItem(ActivityName, ParentActivityID.ToString()));

    for (int i = dtActiveChild .Rows.Count - 1; i >= 0; i--)
    {
        long ActivityChildID = Convert.ToInt64(dtActiveChild .Rows[i][" ActivityID"].ToString());

        if (i != 0)
        {
            ListBox lstBoxChild = new ListBox();
            lstBoxChild.ID = "lstTrack" + ActivityChildID.ToString();
            lstBoxChild.Width = 200;
            lstBoxChild.Height = 200;
            pnlTrack.Controls.Add(lstBoxChild);

            for (int p = 0; p < lstBoxParent.Items.Count; p++)
            {
                lstBoxChild.Items.Add(new ListItem(lstBoxParent.Items[p].Text, lstBoxParent.Items[p].Value));
            }
            TrackingActivity(ActivityChildID, lstBoxChild);
        }
        else
        {
            ParentActivityID = ActivityChildID ;

            goto chk;
        }
    }