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 828125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:40:50+00:00 2026-05-15T03:40:50+00:00

My issue is that I want to display data in a hierarchal structure as

  • 0

My issue is that I want to display data in a hierarchal structure as so:

  • Democrat
    • County Clerk
      • Candidate 1
      • Candidate 2
    • Magistrate
      • Candidate 1
      • Candidate 2
      • Candidate 3

But I’m retrieving the dataset like this:

Party | Office | Candidate
--------------------------------------------
Democrat | County Clerk | Candidate 1
Democrat | County Clerk | Candidate 2
Democrat | Magistrate | Candidate 1
Democrat | Magistrate | Candidate 2
Democrat | Magistrate | Candidate 3

I planned on using nested repeaters, but I need a distinct value of Party, and then distinct values of office name within that party in order to do it.

Are there any .NET functions to easily do what I’m attempting to? Would there be a better way of displaying the information other than repeaters?

Thanks in advance!

  • 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. Editorial Team
    Editorial Team
    2026-05-15T03:40:51+00:00Added an answer on May 15, 2026 at 3:40 am

    If you can modify the stored procedure, I would recommend a result set in the form of an adjacency list:

    ID    Name          ParentID
    1     Democrat      NULL
    2     County Clerk  1
    3     Magistrate    1
    4     Candidate 1   2
    5     Candidate 2   2
    6     Candidate 1   3
    7     Candidate 2   3
    8     Candidate 3   3
    

    It reduces the amount of data retrieved, and allows you to program recursively against the parent-child relationships. You simply start at the root. This approach avoids the hassle of using nested Repeaters by directly building the string literal in a StringBuilder.

    StringBuilder sb = new StringBuilder();
    DataTable dt = new DataTable();
    someDataAdapter.Fill(dt);
    
    // find the roots:
    DataRow[] roots = dt.Select("parentId is null");
    
    sb.Append("<ul>");
    foreach (DataRow child in roots)
    {
        WriteNode(child, sb);
    }
    sb.Append("</ul>");
    
    
    // recursively write out each node
    public static void WriteNode(DataRow row, StringBuilder sb) {
        sb.Append("<li>"); 
        sb.Append(row["Name"]);
    
        // find children rows...
        DataRow[] children = row.Table.Select("parentId = " + row["id"].ToString());
            if (children.Length > 0)
            {
                sb.Append("<ul>");
                foreach (DataRow child in children)
                {
                    WriteNode(child, sb);
                }
                sb.Append("</ul>");
            }
    
            sb.Append("</li>");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See here for my issue: http://jsfiddle.net/FvBqA/126/ My issue is that I want to be
The issue I have is that I want to parse strings in order, so
Here's the issue: I have a list of App names that I want to
I have an issue that (I think) might have to do with scope, but
I am creating a data access layer where I want to handle exceptions that
The title may sound confusing. But here's my issue. I want to show something
We display our data on datagrids, bound to a dataset, which is in turn
I have the following issue: I want to display Tickets from a helpdesk system
EDIT. I missed the one main issue I was having. I want to display
So I have an issue that I'm not 100% sure on how to solve.

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.