Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 155933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:14:35+00:00 2026-05-11T10:14:35+00:00

I have table with pageId, parentPageId, title columns. Is there a way to return

  • 0

I have table with pageId, parentPageId, title columns.

Is there a way to return unordered nested list using asp.net, cte, stored procedure, UDF… anything?

Table looks like this:

PageID    ParentId    Title 1         null        Home 2         null        Products 3         null        Services 4         2           Category 1 5         2           Category 2 6         5           Subcategory 1 7         5           SubCategory 2 8         6           Third Level Category 1 ...   

Result should look like this:

Home Products     Category 1         SubCategory 1             Third Level Category 1         SubCategory 2     Category 2 Services 

Ideally, list should contain <a> tags as well, but I hope I can add it myself if I find a way to create <ul> list.

EDIT 1: I thought that already there is a solution for this, but it seems that there isn’t. I wanted to keep it simple as possible and to escape using ASP.NET menu at any cost, because it uses tables by default. Then I have to use CSS Adapters etc.

Even if I decide to go down the ‘ASP.NET menu’ route I was able to find only this approach: http://aspalliance.com/822 which uses DataAdapter and DataSet 🙁

Any more modern or efficient way?

  • 1 1 Answer
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:14:36+00:00Added an answer on May 11, 2026 at 10:14 am

    Best practice would be to do this using IHierarchyData and IHierarchalEnumerable and DataBind to a custom control which inherits from HierarchalDataBoundControl (this is the base for controls like TreeView).

    However, let’s try for a quick-and-dirty, not-especially-efficient, simple example in c#:

    //class to hold our object graph in memory //this is only a good idea if you have a small number of items //(less than a few thousand) //if so, this is a very flexible and reusable way to represent your tree public class Page {     public string Title {get;set;}     public int ID {get;set;}     public Collection<Page> Pages = new Collection<Page>();      public Page FindPage(int id)     {         return FindPage(this, id);     }      private Page FindPage(Page page, int id)     {         if(page.ID == id)         {             return page;         }         Page returnPage = null;         foreach(Page child in page.Pages)         {             returnPage = child.FindPage(id);             if(returnPage != null)             {                 break;             }         }         return returnPage;     } }  //construct our object graph DataTable data = SelectAllDataFromTable_OrderedByParentIDAscending(); List<Page> topPages = new List<Page>(); foreach(DataRow row in data.Rows) {     Page page = new Page();     page.Title = (string)row['Title'];     page.ID = (int)row['PageID'];     if(row['ParentID'] == null)     {         topPages.Add(page);     }     else     {         int parentID = (int)row['ParentID'];         foreach(Page topPage in topPages)         {             Page parentPage = topPage.FindPage(parentID);             if(parentPage != null)             {                 parentPage.Pages.Add(page);                 break;             }         }     } }  //render to page public override void Render(HtmlTextWriter writer) {     writer.WriteFullBeginTag('ul');     foreach(Page child in topPages)     {         RenderPage(writer, child);     }     writer.WriteEndTag('ul'); }  private void RenderPage(HtmlTextWriter writer, Page page) {     writer.WriteFullBeginTag('li');     writer.WriteBeginTag('a');     writer.WriteAttribute('href', 'url');     writer.Write(HtmlTextWriter.TagRightChar);     writer.Write(page.Title);     writer.WriteEndTag('a');     if(page.Pages.Count > 0)     {         writer.WriteFullBeginTag('ul');         foreach(Page child in page.Pages)         {             RenderPage(writer, child);         }         writer.WriteEndTag('ul');     }     writer.WriteEndTag('li'); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table Page with 2 columns: PageID and OrderByMethod. I also
I have a table with 3 columns - id (pk), pageId (fk), name. I
I have 11 records in the Menu table, only 1 with a PageID set
I have table with around 70 000 rows. There is 6000 rows that i
I have a mysql table like: id, visitorid, pageid When a visitor hits the
I have a Pages table, I have a PagesRoles table with PageId, RoleID that
I have a table of one row with two columns.I want to align content
I have a MySQL table that has a column called title which is a
I used to do ASP (vbscript) Programming, and have recently tried to start using
I have got a table in my MySql database: pageid | text -----------+---------- 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.