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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:09:07+00:00 2026-06-15T14:09:07+00:00

I want to display a tree structure like this: Mission1 Activity1 Project1 Activity2 Mission2

  • 0

I want to display a tree structure like this:

  • Mission1

    • Activity1
      • Project1
    • Activity2
  • Mission2

    • Activity3
      • Project2

But instead I’m getting a list that repeats the parent elements for every activity or project that is different like this:

  • Mission1

    • Activity1
      • Project1
  • Mission1

    • Activity2

I want to group the Activities and Projects under one parent (‘Mission’) element.

Here’s my LINQ query:

var q = from mission in _context.tMissions
                join activity in _context.tActivities on mission.id equals activity.missionId
                join project in _context.tDefaultEventTypes on activity.id equals project.activityId
                where !project.isRemoved && project.defaultCategoryId == 4
                orderby mission.name
                select CreateFrom(project);

        return q.ToList();

I then just bind that to a list and display it on the page. Here’s my aspx:

    <asp:DataList ID="dlTierTypes" runat="server">
      <ItemTemplate>
        <li><%# Eval("Activity.Mission.Name") %></li>
          <ul>
            <li><%# Eval("Activity.Name") %></li>
            <ul>
              <li><%# Eval("Name") %></li>
            </ul>
      </ItemTemplate>
    </asp:DataList>

And the code behind just binds it:

    public void SetTierTree(IEnumerable<DefaultEventType> tierList)
    {
      dlTierTypes.DataSource = tierList;
      dlTierTypes.DataBind();
    }

Not sure how to tackle this exactly.

EDIT – Here’s my new function in the repository.

    public ICollection<DefaultEventType> GetTierTree()
    {
        var q = from mission in _context.tMissions
                join activity in _context.tActivities on mission.id equals activity.missionId
                join project in _context.tDefaultEventTypes on activity.id equals project.activityId
                where !project.isRemoved && project.defaultCategoryId == 4
                orderby mission.name
                select new DefaultEventType(project.tierLevel.TryParseEnum<GanttType>(GanttType.Unknown), DefaultCategoryRepository.CreateFrom(project.tDefaultCategory))
                {
                    //t = new DefaultEventType(project.tierLevel.TryParseEnum<GanttType>(GanttType.Unknown), DefaultCategoryRepository.CreateFrom(project.tDefaultCategory)),
                    AllowNumericSuffix = project.allowNumericSuffix,
                    AttachMilestoneMoniker = project.attachMilestoneMoniker,
                    Description = project.description,
                    Id = project.id,
                    IsReadOnly = project.isReadOnly,
                    IsSticky = project.isSticky,
                    Name = project.name,
                    Sid = project.sid,
                    Style = project.style.TryParseEnum<GanttElementStyle>(GanttElementStyle.Unknown),
                    TimeStamp = project.createdDT,
                    UpdatedTimeStamp = project.updatedDT,
                    Activity = new Activity { Id = activity.id, Name = activity.name, Mission = new Mission { Id = mission.id, Name = mission.name } }
                };

        var q2 = q.GroupBy(row => row.Activity.Mission.Id)
            .Select(group => group.GroupBy(row => row.Activity.Id));

        return q2.Cast<DefaultEventType>().ToList();
    }

But I receive this error when displaying the page:
‘Could not convert from type ‘System.Collections.Generic.List1[System.Linq.IGrouping2[System.Int32,DefaultEventType]]’ to type ‘DefaultEventType’.’

  • 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-15T14:09:09+00:00Added an answer on June 15, 2026 at 2:09 pm

    First you need to adjust the query. The use of GroupBy can greatly help in this example.

    Just take exactly what you have, then group the results by mission. The, for each group, group the missions by activity (this needs to be nested group bys, not sequential group bys).

    var q2 = q.GroupBy(row => row.MissionID)
         .Select(group => group.GroupBy(row => row.ActivityID));
    

    I’m not sure if your provider can do that mapping on the DB end or not; if not throw an AsEnumerable in that query where needed.

    Next, you’ll need to change how you render the data to reflect this change.

    Rather than a single DataList you’ll need 3 nested data lists. You’ll bind the whole query to the outer level which displays the mission, then subscribe to the data bound event to set the inner-group as the data source of that instance of the inner data list. Then, in that inner data list, display the activity and bind the innermost group level to the innermost DataList, which can bind the project name normally.

    Also, you may consider using a TreeView to render the data structure instead of a DataList, since a TreeView is designed to render trees. I’m not sure if you needed to reject it for some reason or just didn’t consider it, but it would probably be easier to work with. If you do go that route the query will still be modified as I suggested, you just won’t need any nested ASP controls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a deep structure that I would like to display as a tree
I want to display MySQL results like this in a PHP/HTML table. Maybe add
I want to display a file tree similarly to java2s.com 'Create a lazy file
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
In the header of the django admin, I want display a link. This link
I want to display result of this javascript in a label control on my
I've been using tomahawk (1.1.11) for a project. I want to display a tree
I have Adjacency list mode structure like that and i want to count all
I want to display a tree view in my page. For that i will
I'm using Core Data and I have a file-folder tree-like structure. So I've created

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.