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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:23:40+00:00 2026-05-26T20:23:40+00:00

I have a simple foreach loop that goes through the productID’s I have stored

  • 0

I have a simple foreach loop that goes through the productID’s I have stored in a user’s basket and looks up the product’s details from the database.

As you can see from my code, what I have at present will return the very last item on screen – as the variable is overwritten within the loop. I’d like to be able to concat this so that I can display the product details for the items only in the basket.

I know I could do something very easy like store only ProductIDs in the repeater I use and onitemdatabound call the database there but I’d like to make just one database call if possible.

Currently I have the following (removed complex joins from example, but if this matters let me know):

IQueryable productsInBasket = null;
    foreach (var thisproduct in store.BasketItems)
    {
        productsInBasket = (from p in db.Products
                                 where p.Active == true && p.ProductID == thisproduct.ProductID
                                 select new
                                 {
                                     p.ProductID,
                                     p.ProductName,
                                     p.BriefDescription,
                                     p.Details,
                                     p.ProductCode,
                                     p.Barcode,
                                     p.Price
                                 });
    }

    BasketItems.DataSource = productsInBasket;
    BasketItems.DataBind();

Thanks for your help!

  • 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-26T20:23:41+00:00Added an answer on May 26, 2026 at 8:23 pm

    It sounds like you really want something like:

    var productIds = store.BasketItems.Select(x => x.ProductID).ToList();
    var query = from p in db.Products
                where p.Active && productIds.Contains(p.ProductID)
                select new
                {
                    p.ProductID,
                    p.ProductName,
                    p.BriefDescription,
                    p.Details,
                    p.ProductCode,
                    p.Barcode,
                    p.Price
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So...I have this scenario where I have a Foreach loop that loops through a
in my asp.net mark up I have a foreach loop that iterates through a
I have an extremely simple JSON object that looks like the following: var data
I have this simple loop: foreach ($links as $link) { echo '<div>'; echo '<table>';
I have a pretty simple case which I started solving using foreach(), but then
I have a very simple query $this->db->select('id, title'); $this->db->order_by('id', 'DESC'); $query = $this->db->get('journal'); foreach($query->result()
I have simple win service, that executes few tasks periodically. How should I pass
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have simple table that has about 80 rows, which I populate dynamically using
basically I have a for loop that give me two values, id, and value

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.