private void BindMenu()
{
if (TreeView1.Nodes.Count == 0)
{
IntertechDBDataContext db = new IntertechDBDataContext();
var pages = db.Pages;
foreach (Page page in pages.Where(p => p.ParentPageID == null))
{
TreeNode node = new TreeNode();
node.Value = page.PageID.ToString();
node.Text = page.Title;
node.NavigateUrl = "~/Admin/Page/Details.aspx?id=" + node.Value;
TreeView1.Nodes.Add(node);
BindChilds(node, page.Pages);
}
}
private static void BindChilds(TreeNode parentNode, EntitySet
{
if (childs.Count > 0)
{
foreach (Page page in childs)
{
TreeNode node = new TreeNode();
node.Value = page.PageID.ToString();
node.Text = page.Title;
node.NavigateUrl = "~/Admin/Page/Details.aspx?id=" + node.Value;
parentNode.ChildNodes.Add(node);
BindChilds(node, page.Pages);
}
}
}
recursive function
Gönderen
pantepember
8 Eylül 2009 Salı
Etiketler: linq , recursive function , treeview