title: Saving Data in a Repeater to a Database in SQL in a Single Row
body: <p>I'm facing a minor problem in ASP.NET. I will explain in detail below.</p>
  
  <ul>
  <li>I am saving the products in the tbl_ShopCart to the tbl_Order.</li>
  <li>There can be more than 1 product, because I use repeater for shop cart.</li>
  <li>For example: My shop cart have 2 products and I push button to complete shopping and I have saved the data for the tbl_Order. But the total price is recorded separately for the two products. And I want to show the total price in one line for two or more products.</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/xlcS6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xlcS6.png" alt="enter image description here"></a>
  My design code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table class="table shop-cart text-center"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th class="first"&gt;&lt;/th&gt;
              &lt;th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text"&gt;Product Name&lt;/th&gt;
              &lt;th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text"&gt;Price&lt;/th&gt;
              &lt;th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text"&gt;Piece&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound"&gt;
              &lt;ItemTemplate&gt;
                  &lt;tr&gt;
                      &lt;asp:Label ID="LblShopCartID" runat="server" Text='&lt;%#Eval("shopcartid") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;asp:Label ID="LblProductID" runat="server" Text='&lt;%#Eval("productid") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;td class="product-thumbnail text-left"&gt;&lt;asp:Image ID="ImgProductImage" runat="server" Height="150px" Width="150px" ImageUrl='&lt;%#Eval("productimage") %&gt;' /&gt;&lt;/td&gt;
                      &lt;td class="text-left"&gt;&lt;asp:Label ID="LblProductName" runat="server" Text='&lt;%#Eval("productname") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td class="text-left"&gt;&lt;asp:Label ID="LblPrice" runat="server" Text='&lt;%#Eval("price") %&gt;'&gt;&lt;/asp:Label&gt; TL&lt;/td&gt;
                      &lt;td class="product-subtotal text-left"&gt;&lt;asp:Label ID="LblPiece" runat="server" Text='&lt;%#Eval("piece") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:Repeater&gt;
          &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:aytasarimConnectionString %&gt;" SelectCommand="SELECT * FROM [tbl_ShopCart] WHERE ([userid] = @userid)"&gt;
              &lt;SelectParameters&gt;
                  &lt;asp:SessionParameter Name="userid" SessionField="userid" Type="Int32" /&gt;
              &lt;/SelectParameters&gt;
          &lt;/asp:SqlDataSource&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;table class="table cart-total"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;th class="padding-two text-right no-padding-right text-uppercase font-weight-600 letter-spacing-2 text-small xs-no-padding"&gt;Shop Cart Total: &lt;/th&gt;
              &lt;td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text xs-no-padding"&gt;&lt;asp:Label ID="LblShopCartTotal" Text="" runat="server"&gt;&lt;/asp:Label&gt; ₺&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th class="padding-two text-right no-padding-right text-uppercase font-weight-600 letter-spacing-2 text-small xs-no-padding"&gt;Cargo Price: &lt;/th&gt;
              &lt;td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text text-small xs-no-padding"&gt;&lt;asp:Label ID="LblCargoPrice" runat="server" Text=""&gt;&lt;/asp:Label&gt; ₺&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="total"&gt;
              &lt;th class="padding-two text-uppercase text-right no-padding-right font-weight-600 text-large xs-no-padding"&gt;Last Total: &lt;/th&gt;
              &lt;td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text text-large no-letter-spacing xs-no-padding"&gt;&lt;asp:Label ID="LblTotalPrice" runat="server" Text=""&gt;&lt;/asp:Label&gt; ₺&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>View on browser:
  <a href="https://i.stack.imgur.com/z2Q9m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z2Q9m.png" alt="enter image description here"></a>
  My aspx.cs code:</p>
  
  <pre><code>protected void BtnCompleteOrder_Click(object sender, EventArgs e)
  {
      foreach(RepeaterItem item in Repeater1.Items)
      {
          if(item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
          {
              Label lblproductid = (Label)item.FindControl("LblProductID");
              Image imgproductimage = (Image)item.FindControl("ImgProductImage");
              Label lblproductname = (Label)item.FindControl("LblProductName");
              Label lblprice = (Label)item.FindControl("LblPrice");
              Label lblpiece = (Label)item.FindControl("LblPiece");
              function.cmd("INSERT INTO tbl_Order(userid, productid, name, surname, email, identificationnumber, phone, productimage, productname, piece, cargo, totalprice, paymenttype, orderdate) VALUES('" + Session["userid"] + "', '" + lblproductid.Text + "', '" + Session["name"] + "', '" + Session["surname"] + "', '" + Session["email"] + "', '" + Session["identificationnumber"] + "', '" + Session["phone"] + "', '" + imgproductimage.ImageUrl + "', '" + lblproductname.Text + "', '" + lblpiece.Text + "', '" + Session["cargo"] + "', '" + LblTotalPrice.Text + "', '" + DrpDwnPaymentType.Text + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')");
          }
      }
  }
  
  // I add the cargo price on top of the total price, which gives us the lasttotal.
  decimal total = 0;
  decimal lasttotal = 0;
  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      DataRowView item = e.Item.DataItem as DataRowView;
      total += Convert.ToDecimal(item["price"]) * Convert.ToDecimal(item["piece"]);
      LblShopCartTotal.Text = total.ToString();
  
      lasttotal = total + Convert.ToDecimal(LblCargo.Text);
      LblTotalPrice.Text = lasttotal.ToString();
  }
  </code></pre>
  
  <p>How can I show the total price in one line for two or more products? Any ideas?</p>