我的 TreeView 中存在一个问题,我只能填充一个级别的子级,例如
Parent Level 0
---->Child Level 1
---->Child Level 2 //here i'm not able to get this level
我的问题是我无法在 TreeView 中获得 Child Level 2 这是我的aspx.cs代码
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt0 = this.GetData("select ClientId,C_Name from clientdetails");
this.PopulateTreeView(dt0, 0, null);
TreeView1.Attributes.Add("onclick", "return OnTreeClick(event)");
TreeView1.CollapseAll();
}
}
private void PopulateTreeView(DataTable dtParent, int parentId, TreeNode treeNode)//this is for parent Level 0 node
{
foreach (DataRow row in dtParent.Rows)
{
TreeNode child = new TreeNode
{
Text = row["C_Name"].ToString(),
Value = row["ClientId"].ToString()
};
if (parentId == 0)
{
//TreeNode node = new TreeNode();
//node.Text = "par";
TreeView1.Nodes.Add(child);
DataTable dtChild1 = this.GetData("SELECT location_id, Location_name FROM client_locations WHERE client_id = " + child.Value);
PopulateTreeView1(dtChild1, int.Parse(child.Value), child);
}
else
{
treeNode.ChildNodes.Add(child);
}
}
}
private void PopulateTreeView1(DataTable dtParent, int parentId, TreeNode treeNode)//this is for Child Level 1 node
{
foreach (DataRow row in dtParent.Rows)
{
TreeNode child = new TreeNode
{
Text = row["Location_name"].ToString(),
Value = row["location_id"].ToString()
};
if (parentId == 0)
{
TreeView1.Nodes.Add(child);
DataTable dtChild = this.GetData("SELECT contactperson_id, concat(fname,' ',lname)as name FROM contactpersons WHERE Location_id = " + child.Value);
PopulateTreeView2(dtChild, int.Parse(child.Value), child);
}
else
{
treeNode.ChildNodes.Add(child);
}
}
}
private void PopulateTreeView2(DataTable dtParent, int parentId2, TreeNode treeNode)//this is for Child Level 2 node here its not working
{
foreach (DataRow row in dtParent.Rows)
{
TreeNode child = new TreeNode
{
Text = row["contactperson_id"].ToString(),
Value = row["name"].ToString()
};
if (parentId2 == 0)
{
TreeView1.Nodes.Add(child);
DataTable dtChild = this.GetData("SELECT contactperson_id, concat(fname,' ',lname)as name FROM contactpersons WHERE Location_id = " + child.Value);
//PopulateTreeView2(dtChild, int.Parse(child.Value), child);
}
else
{
treeNode.ChildNodes.Add(child);
}
}
}
我应该修改什么才能让我的孩子达到2级水平?