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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:50:59+00:00 2026-05-26T21:50:59+00:00

This is what i’m trying to accomplish. I want to select only distinct values

  • 0

This is what i’m trying to accomplish. I want to select only distinct values from all Rows in Column[0].

Then I want to get all the distinct values from column[2] and group them on column[0].

so basically i got a DataTable like so:

Fruit|Apples
Fruit|Pears
Vegetables|Peas
Vegetables|Carrots

so I want to do a foreach on the distinct values, so I would Enumerate Fruit once and then pick up Apples and Pears, and VegeTables once and pick up Peas and Carrots.

I’m doing this to create Accordion Panes, where I want to group my results under one header, the below code does such, however, it creates two panes of Fruit because it does not realize it already went though fruit.

 foreach (DataRow dtrow in dtTable.Rows)
        {
            string idRow = dtrow[0].ToString();
            AccordionPane currentPane = new AccordionPane();
            currentPane.ID = "AccordionPane" + Guid.NewGuid().ToString();
            currentPane.HeaderContainer.Controls.Add(new LiteralControl(dtrow[0].ToString()));
            foreach(DataRow dtRow2 in dtTable.Rows)
            {
                if(dtRow2[0].ToString() == idRow)
                {
                    currentPane.ContentContainer.Controls.Add(new LiteralControl(dtRow2[1].ToString()));
                }
            }
            NavigateAccordion.Panes.Add(currentPane);
        }
  • 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-26T21:51:00+00:00Added an answer on May 26, 2026 at 9:51 pm

    You can accomplish this easily when using linq, see for yourself:

    var groupedRows = from row in dtTable.Rows.AsEnumerable()
                      group row by row[0] into grouped
                      select grouped;
    
    foreach (var group in groupedRows)
    {
        currentPane = new AccordionPane();
        currentPane.HeaderContainer.Controls.Add(group.Key.ToString());
    
        foreach (var row in group)
        {
            currentPane.ContentContainer.Controls.Add(row[1].ToString());
        }   
    }
    

    Or if you want to stick with your current non-linq approach:

    foreach (DataRow dtrow in dtTable.Rows) 
            { 
                bool skip = false;
    
                foreach (var pane in NavigateAccordion.Panes)
                {
                    if (pane.HeaderContainer.Controls[0].Text == dtRow[0].ToString())
                    {
                        skip = true;
                        break;
                    }
                }
    
                if (!skip)
                {
                    string idRow = dtrow[0].ToString(); 
                    AccordionPane currentPane = new AccordionPane(); 
                    currentPane.ID = "AccordionPane" + Guid.NewGuid().ToString(); 
                    currentPane.HeaderContainer.Controls.Add(new LiteralControl(dtrow[0].ToString())); 
                    foreach(DataRow dtRow2 in dtTable.Rows) 
                    { 
                        if(dtRow2[0].ToString() == idRow) 
                        { 
                            currentPane.ContentContainer.Controls.Add(new LiteralControl(dtRow2[1].ToString())); 
                        } 
                    } 
                    NavigateAccordion.Panes.Add(currentPane); 
                }
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This works fine, but I want to make it prettier - and accommodate all
This code below allows me to find the word error in all my files
For some reason, after submitting a string like this Jack’s Spindle from a text
This is as close as I've gotten to successfully populating an expandable listview from
This is a super simple issue that I can't figure out. I want to
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This would list numbers 5.0 to 7.0 in a drop select menu: <%= f.select
This is my database table. Now I want to combine Branch_Id, Acc_no and Acc_Type
I have a text area in my form which accepts all possible characters from

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.