Christineeve
Programmer
Dear Coding Gurus:
My code is created the childnode twice. I cannot figure out what I'm doing wrong. I should have a tree that looks like this:
Subject -
Parent
Child
Subject
Parent
Child
What my code is doing is populating the child twice.
My code is created the childnode twice. I cannot figure out what I'm doing wrong. I should have a tree that looks like this:
Subject -
Parent
Child
Subject
Parent
Child
What my code is doing is populating the child twice.
Code:
protected void trvMsgBoard_TreeNodePopulate(
object sender, TreeNodeEventArgs e)
{
if (e.Node.ChildNodes.Count == 0)
{
switch (e.Node.Depth)
{
case 0:
PopulateThread(e.Node);
break;
case 1:
PopulateSubTopics(e.Node);
break;
}
}
}
//State what level the tree node is on for the developer.
void PopulateThread(TreeNode node) //Parent Node
{
DataTable dtSRS = DAL.Oracle_ReturnDataTable_SQLString_NoParams("SELECT WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID," +
" WDSDEV.DZR_FORUM_TOPIC.TOPIC_TOPIC," +
" WDSDEV.DZR_FORUM_TOPIC.TOPIC_DATETIME" +
" FROM WDSDEV.DZR_FORUM_TOPIC", Oracle_connstr1, "dtSRS");
using (DataSet dsSRS = new DataSet())
{
dsSRS.Tables.Add(dtSRS);
if (dsSRS.Tables.Count > 0)
foreach (DataRow row in dsSRS.Tables[0].Rows)
{
TreeNode NewNode = new TreeNode(row["TOPIC_TOPIC"].ToString(), row["TOPIC_TOPIC"].ToString())
{ PopulateOnDemand = true,
SelectAction = TreeNodeSelectAction.Expand };
node.ChildNodes.Add(NewNode);
}
}
}
void PopulateSubTopics(TreeNode node) //child not
{
DataTable dtPST = DAL.Oracle_ReturnDataTable_SQLString_NoParams(
" SELECT * " +
" FROM WDSDEV.DZR_FORUM_SUB_TOPIC " +
" INNER JOIN WDSDEV.DZR_FORUM_TOPIC" +
" ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_SUB_TOPIC.TOP_ID" +
" INNER JOIN WDSDEV.DZR_FORUM_AUTHOR" +
" ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_AUTHOR.FK_TOP_ID" , Oracle_connstr1, "dtPST");
using (DataSet dsPST = new DataSet())
{
dsPST.Tables.Add(dtPST);
if (dsPST.Tables.Count > 0)
foreach (DataRow row in dsPST.Tables[0].Rows)
{
TreeNode NewNode = new TreeNode(row["SUBTOP_TOPIC"].ToString(), row["SUBTOP_TOPIC"].ToString());
NewNode.PopulateOnDemand = false;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);
}
}
}