title: Prevent adding duplicateitems to a List from a DataTable
body: <p>I am writing a mass ordering system and one of the requirements is being able to type in multiple quantities of various products and having to add them all at once to the cart. 
  I am using a list view to populate my products according to the food groups and am only displaying 10 products at a time. </p>
  
  <p>So what I need to do is to store the quantity input into the List. </p>
  
  <p>How I am trying to do it is to populate a DataTable with the current products. Loop throw that Datatable and add the products that have quantities to the List when the page changes or the client chooses the next food group and when the add to cart button is clicked it adds all the items in the List to the check out table in my MySQL table.</p>
  
  <p>Unless there is a different and much m=simpler way to populate the list view without the DataTable.</p>
  
  <p><strong>This is the List view</strong></p>
  
  <pre><code>                            OnPagePropertiesChanging="lv_groups_PagePropertiesChanging" DataKeyNames="id" OnSelectedIndexChanging="lv_groups_SelectedIndexChanging"&gt;
                              &lt;LayoutTemplate&gt;
                                  &lt;table class="tbl-lv" style="width: 100%; margin-top: -15px; margin-bottom: -15px; padding:10px"&gt;
                                      &lt;tr style="height:30px"&gt;
                                          &lt;th style="width: 50%;"&gt;Product
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Unit Size
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Unit
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Price (per unit)
                                          &lt;/th&gt;
                                          &lt;th style="width: 20%"&gt;QTY
                                          &lt;/th&gt;
                                      &lt;/tr&gt;
                                      &lt;asp:PlaceHolder runat="server" ID="groupPlaceHolder1"&gt;&lt;/asp:PlaceHolder&gt;
                                      &lt;tr style="height:30px"&gt;
                                          &lt;td colspan="5"&gt;
                                              &lt;asp:DataPager ID="DataPager1" runat="server" PagedControlID="lv_groups" PageSize="10"&gt;
                                                  &lt;Fields&gt;
                                                      &lt;asp:NextPreviousPagerField ShowLastPageButton="False" ShowNextPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" /&gt;
                                                      &lt;asp:NumericPagerField ButtonType="Button" RenderNonBreakingSpacesBetweenControls="false" NumericButtonCssClass="btn btn-primary" CurrentPageLabelCssClass="btn disabled" NextPreviousButtonCssClass="btn" /&gt;
                                                      &lt;asp:NextPreviousPagerField ShowFirstPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" /&gt;
                                                  &lt;/Fields&gt;
                                              &lt;/asp:DataPager&gt;
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/table&gt;
                              &lt;/LayoutTemplate&gt;
                              &lt;EmptyDataTemplate&gt;
                                  &lt;table class="tbl-lv" style="width: 100%;"&gt;
                                      &lt;tr&gt;
                                          &lt;th style="width: 50%;"&gt;Product
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Unit Size
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Unit
                                          &lt;/th&gt;
                                          &lt;th style="width: 10%"&gt;Price
                                          &lt;/th&gt;
                                          &lt;th style="width: 20%"&gt;QTY
                                          &lt;/th&gt;
                                      &lt;/tr&gt;
                                      &lt;asp:PlaceHolder runat="server" ID="groupPlaceHolder1"&gt;&lt;/asp:PlaceHolder&gt;
                                      &lt;tr&gt;
                                          &lt;td colspan="5"&gt;
                                              &lt;asp:DataPager ID="DataPager1" runat="server" PagedControlID="lv_groups" PageSize="10"&gt;
                                                  &lt;Fields&gt;
                                                      &lt;asp:NextPreviousPagerField ShowLastPageButton="False" ShowNextPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" /&gt;
                                                      &lt;asp:NumericPagerField ButtonType="Button" RenderNonBreakingSpacesBetweenControls="false" NumericButtonCssClass="btn btn-primary" CurrentPageLabelCssClass="btn disabled" NextPreviousButtonCssClass="btn" /&gt;
                                                      &lt;asp:NextPreviousPagerField ShowFirstPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" /&gt;
                                                  &lt;/Fields&gt;
                                              &lt;/asp:DataPager&gt;
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/table&gt;
                              &lt;/EmptyDataTemplate&gt;
                              &lt;GroupTemplate&gt;
                                  &lt;tr style="height:30px"&gt;
                                      &lt;asp:PlaceHolder runat="server" ID="itemPlaceHolder1"&gt;&lt;/asp:PlaceHolder&gt;
                                  &lt;/tr&gt;
                              &lt;/GroupTemplate&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:HiddenField ID="HiddenField1" Value='&lt;%# Eval("id") %&gt;' runat="server" /&gt;
                                  &lt;td style="width: 50%"&gt;
                                      &lt;%# Eval("product_description") %&gt;
                                  &lt;/td&gt;
                                  &lt;td style="width: 10%"&gt;
                                      &lt;%# Eval("unit_size", "{0:#### }") %&gt;
                                  &lt;/td&gt;
                                  &lt;td style="width: 10%"&gt;
                                      &lt;%# Eval("unit") %&gt;
                                  &lt;/td&gt;
                                  &lt;td style="width: 10%"&gt;
                                      &lt;%# Eval("price") %&gt;
                                  &lt;/td&gt;
                                  &lt;td style="width: 20%"&gt;
                                      &lt;asp:TextBox runat="server" ID="txtQty" ForeColor="Black" Width="80%" Text='&lt;%# Eval("qty") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                  &lt;/td&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>This is the code in which I'm trying to add items to the list (am still green in programming so any help would be appreciated). What do I put in the <code>if</code> statement?</p>
  
  <pre><code>    {
          List&lt;CartItems&gt; items = new List&lt;CartItems&gt;();
  
          DataTable CartTable = pd.dt_products_qty(helpers.ConnectionString, product_group_id, order_id);
  
          if (CartTable != null &amp;&amp; CartTable.Rows.Count &gt; 0)
          {
              foreach (DataRow row in CartTable.Rows)
              {
                  if ()
                  {
                      items.Add(new CartItems { id=row["id"].ToString(), product=row["product_description"].ToString(), unitSize=row["unit_size"].ToString(), unit=row["unit"].ToString(), price=row["price"].ToString(), qty=row["qty"].ToString() });
                  }
              }
          }
          return items;
      }
  </code></pre>