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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:26+00:00 2026-05-25T18:13:26+00:00

i ve 3 tables in my database : item , group , groupdetail ;

  • 0

i ve 3 tables in my database : item,group,groupdetail;

in table item there are 2 fields : id,item_name (bigint”long”,string)

in table group there are 2 fields : id,group_name (bigint,string)

in table group_details there are 3 fields : id,group_id,item_id (bigint,bigint,bigint)

group_id is nullable cause some items have no groups.

what i want to do is listing the names of groups where the items that has a group “group_name” ordered by item_id and also in the same list i wanna show the item names which has no group and both of them should be ordered by item_id

i can also fill dropdowns with jquery if required for this action but i’m brain freezed with listing part.

controller

 var data = from guru in dataContext.group_details select guru;

 var itemsWithoutGroup = data.Where(c => c.group_id == null).OrderBy(c => c.item_id).Where(c => c.item_id == c.item.id).Select( c=>c.item.item_name);

 var groups = data.Where(c => c.group_id != null).OrderBy(c => c.item_id).Where(c => c.group_id  == c.group.id).Select( c=>c.group.group_name);

 var grandlist = // i wanna do smt here to list both in one dropdown ordered by item_id

view

@Html.DropDownList("GroupDetails", new SelectList((System.Collections.IEnumerable)ViewData["GroupDetailedList"], "id", "item_id"))

EDIT:

To be more specific about it..

Group-1 
Group-2
Item-9
Group-3
Item-15
Group-4

So this is how the dropdown should look like! Items with no groups should be listed too with the item groups and be ordered by item_id..

  • 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-25T18:13:26+00:00Added an answer on May 25, 2026 at 6:13 pm

    The statement i would use is:

    var groupswithItems = (from groupdetail in group_details select groupdetail.group_id
                         join group in groups groupdetail.group_id equals group.id
                         orderby groupdetail.item_id
                         select new SelectListItem {Text= group.name, Value= group.id.ToString() }).ToList()
    
    var itemswithotgroups = (from item in items orderby item.id select new SelectListItem { Text= item.name, Value= item.id.ToString() }).ToList()
    
    ViewBag.Combined = groupswithItems.union(itemswithotgroups);
    

    This would give you the list from all groups that are in group detail (those contain items i presume) and convert it to object that Dropdownlist can handle

    @Html.DropDownList("GroupDetails", ViewBag.groups as List<SelectListItem>))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database (NexusDB (supposedly SQL-92 compliant)) which contains and Item table, a
When creating database tables I'm often stumped when trying to name my time/date/timestamp fields.
I have 2 tables in my database: CREATE TABLE [items]( [item_id] [int] IDENTITY(1,1) NOT
I have items and itemgroup tables in my database: CREATE TABLE [items]( [item_id] [int]
I've 3 different database tables that have the same 5 fields but those does
DDL for Database Tables: Users: id - int - identity name - varchar -
Assuming two database tables: Funds and Prices , in which Funds hasMany Prices .
I have designed database tables (normalised, on an MS SQL server) and created a
I have two database tables with the following structure: actions: action_id int(11) primary key
I have 3 database tables, all of them have the same 5 columns. They

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.