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

  • Home
  • SEARCH
  • 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
  • 0 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

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Just do a Replace in Files from the Search menu,… May 11, 2026 at 12:33 pm
  • added an answer This purely depends on the type of application you are… May 11, 2026 at 12:33 pm
  • added an answer You might consider not setting up those data classes within… May 11, 2026 at 12:33 pm

Related Questions

I have a table of paged data, along with a dynamically created pager (server-side
I have table with 50 entries (users with such details like Name Surname Location
I have a table with more than a millon rows. This table is used
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
I have a table with a 'filename' column. I recently performed an insert into
The concept So, I've already made (upgraded actually) this website with its own Content
I have three tables tag , page , pagetag With the data below page
I want to list the recent activities of a user on my site without
Let's say I have four tables: PAGE , USER , TAG , and PAGE-TAG

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.