madhu goud

madhu goud

  • NA
  • 36
  • 13.5k

How to retrieve tree view based on id from database table

Jul 8 2016 1:20 AM
am binding tree view from database ,i have 4 parents with their childs in my tree view am binding all parents with childs. But i want to bind only a particular parent with their childs , how to write query for that
My table

EmpID Name ReportsTo
1 Accounts 0
2 Branches 0
3 Loans 1
4 Incomes 2

Accounts, branches are parents loans incomes their childs
what is the query to return Accounts with childs
 
@helper GetTreeView(List<AccountsPageLayout.MasterNode> siteMenu, int parentID)
{
foreach (var i in siteMenu.Where(a => a.ReportsTo.Equals(parentID)))
{
<li>
@{var submenu = siteMenu.Where(a => a.ReportsTo.Equals(i.EmpID)).Count();}
@if (submenu > 0)
{
<span class="collapse collapsible">&nbsp;</span>
}
else
{
<span style="width:15px; display:inline-block">&nbsp;</span>
}
<span>
<a href="#">@i.Name</a>
@*<a href="@i.EmpID">@i.Name</a>*@
</span>
@if (submenu > 0)
{
<ul>
@Treeview.GetTreeView(siteMenu, i.EmpID)
@* Recursive Call for Populate Sub items here*@
</ul>
}
</li>
}
}
 

Answers (3)