Add links to subpages when page is empty

Topics: ASP.NET 2.0
Apr 21, 2008 at 3:08 PM
Edited Apr 21, 2008 at 3:10 PM
This is probably not relevant to most of you, but if someone is using the hierarchical menu that I once did http://www.jonah.carneskog.com/post/Blogengine-Menu-Usercontrol.aspx, you might end up having empty pages when you have added subpages to it.

If you change the code in Pages.aspx.cs on row 63 to this, it will add links to all subpages on that page.

else if (arg.Body != "No text")
{
divText.InnerHtml = arg.Body;
}
else
{

BlogEngine.Core.Page thisPage = BlogEngine.Core.Page.GetPage(id);
System.Collections.Generic.List<BlogEngine.Core.Page> allPages = BlogEngine.Core.Page.Pages;

allPages.Sort(delegate(BlogEngine.Core.Page p1, BlogEngine.Core.Page p2)
{
return p2.DateCreated.CompareTo(p1.DateCreated);
});

StringBuilder sb = new StringBuilder();
sb.Append("<div style=\"padding-left:20px\">");
foreach (BlogEngine.Core.Page p in allPages)
{
if (p.Parent.ToString() == id.ToString())
sb.Insert(0, string.Format("<br /><a href=\"{0}\">{1}</a>", p.RelativeLink, p.Title));

}
sb.Append("</div>");
divText.InnerHtml = sb.ToString();
}

You can see an example here http://www.jonah.carneskog.com/page/Musik.aspx