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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:41:15+00:00 2026-06-08T03:41:15+00:00

I have topic data looking like this: 010000 <- Top level header 010100 A

  • 0

I have topic data looking like this:

010000 <- Top level header
010100 A <- Sub level header
010101 B <- Clickable item in the select list
010102 C <- Clickable item in the select list
010103 D <- Clickable item in the select list
010200 E <- Sub level header
010201 F <- Clickable item in the select list
010202 G <- Clickable item in the select list

Currently I am using the following code to make a select list that shows everthing:

var topics = contentService.Get(accountID + "06000").OrderBy(o => o.Order);
foreach (Content topic in topics) {
    txt += "<option value='" + topic.RowKey + "'>" + topic.Name + "</option>\n";
}

Is there a way I can change this so that:

  • The top level headers are not part of the select list? in other words every row that ends in “0000” is not put into the topics variable.
  • The sub level headers appear as groups in the select list.

Groups like this:

<select>
  <optgroup label="A">
      <option value="010101">B</option>
      <option value="010102">C</option>
      <option value="010103">D</option>
  </optgroup>
  <optgroup label="E">
      <option value="010201">F</option>
      <option value="010202">G</option>
  </optgroup>
</select>

I hope someone can help. I think maybe I can do the limiting but I don’t know how to do the start and end grouping.

  • 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-06-08T03:41:17+00:00Added an answer on June 8, 2026 at 3:41 am

    To simplify matters a bit, let’s assume that your topics are defined in a following List:

    List<Tuple<string, string>> topics = new List<Tuple<string, string>>
    {
        Tuple.Create("010000", string.Empty),
        Tuple.Create("010100", "A"),
        Tuple.Create("010101", "B"),
        Tuple.Create("010102", "C"),
        Tuple.Create("010103", "D"),
        Tuple.Create("010200", "E"),
        Tuple.Create("010201", "F"),
        Tuple.Create("010202", "G"),
    };
    

    Then, you could simply iterate over each topic and build your HTML step-by-step:

    XElement select = new XElement("select");
    XElement optGroup = null;
    
    foreach (var topic in topics)
    {
        // skip root topic
        if (!topic.Item1.EndsWith("0000"))
        {
            // optgroup
            if (topic.Item1.EndsWith("00"))
            {
                optGroup = new XElement("optgroup", new XAttribute("label", topic.Item2));
                select.Add(optGroup);
            }
            // option
            else if (optGroup != null)
            {
                optGroup.Add(new XElement("option", new XAttribute("value", topic.Item1), new XText(topic.Item2)));
            }
        }
    }
    
    Console.WriteLine(select);
    

    You’ll get a following console output:

    <select>
        <optgroup label="A">
            <option value="010101">B</option>
            <option value="010102">C</option>
            <option value="010103">D</option>
        </optgroup>
        <optgroup label="E">
            <option value="010201">F</option>
            <option value="010202">G</option>
        </optgroup>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at this forum on this topic for a while now
I have googled the topic for a while but haven't found what I'm looking
I have searched this topic on google a bit and seen some best practices.
I have encountered this topic lately and couldn't understand why they are needed. Can
I have read some posts about this topic and the answers are comet, reverse
There have been many debates about this topic already here, but none of them
I have been looking at the unit testing topic and honestly I have never
I have the following code to listen firefox quit-application event observe: function(subject, topic, data)
I have researched this topic for months now with no success. Many posts say
Hopefully this doesn't fall under general discussion topic, since I'd like it to be

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.