title: How to replace duplicated value from a table to "quantity"?
body: <p>Im trying to make a typical webshop, got everything worked out so far, but I got this following issue: <strong>How do I replace duplicate database-value in a List to quantity instead, and list them into ListView?</strong> E.g. if I add two of same product into my cart, I want to be able to show quantity instead showing two of same product in the cart-list.</p>
  
  <p>PS: Im listing my results in ListView.</p>
  
  <p>(Form_Load for cart):</p>
  
  <pre><code>using (eShopEntities db = new eShopEntities()){
  
              var list = new List&lt;Product&gt;(db.Products.ToList());
  
              var listFilter = new List&lt;Product&gt;(); 
  
              foreach (var id in list)
              {
                  foreach (var Sessions in SessionData)//got selected products stored in sessions
                  {
                      if (id.ID == Sessions)
                      {
  
                          listFilter.Add(id); //Add all selected products(via session)
                      }
                  }
              }
  
              int TotSum = 0;
              foreach (var sum in listFilter)
              {
                  TotSum = TotSum + sum.Price;
  
              }
  
              cartListView.DataSource = listFilter; cartListView.DataBind();
  
              lblSum.Text = TotSum.ToString();
  
  
             }
  </code></pre>
  
  <p>Right now, everything is listed in aspx. But Im not sure how to replace duplicated into quantities from listFilter <strong>AND</strong> send the quanties-data along with the result from listFilter into cartListWiev togheter.</p>
  
  <p>My Product table(SQL): ID(PK), Name, ImagePath, Price, and CatergoryID(FK)</p>
  
  <p>Thanks</p>