Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止从DataTable向列表中添加重复项_C#_Mysql_Asp.net_Loops - Fatal编程技术网

C# 防止从DataTable向列表中添加重复项

C# 防止从DataTable向列表中添加重复项,c#,mysql,asp.net,loops,C#,Mysql,Asp.net,Loops,我正在编写一个大批量订购系统,其中一个要求是能够输入多个数量的各种产品,并且必须一次将它们全部添加到购物车中。 我使用列表视图根据食物组填充我的产品,一次只显示10种产品 所以我需要做的是将输入的数量存储到列表中 我试图做的是用当前产品填充数据表。当页面更改或客户端选择下一个食物组时,循环抛出该数据表并将具有数量的产品添加到列表中,当单击“添加到购物车”按钮时,它会将列表中的所有项目添加到my MySQL表中的签出表中 除非有一种不同且更简单的方法来填充列表视图而不使用DataTable 这是列

我正在编写一个大批量订购系统,其中一个要求是能够输入多个数量的各种产品,并且必须一次将它们全部添加到购物车中。 我使用列表视图根据食物组填充我的产品,一次只显示10种产品

所以我需要做的是将输入的数量存储到列表中

我试图做的是用当前产品填充数据表。当页面更改或客户端选择下一个食物组时,循环抛出该数据表并将具有数量的产品添加到列表中,当单击“添加到购物车”按钮时,它会将列表中的所有项目添加到my MySQL表中的签出表中

除非有一种不同且更简单的方法来填充列表视图而不使用DataTable

这是列表视图

                            OnPagePropertiesChanging="lv_groups_PagePropertiesChanging" DataKeyNames="id" OnSelectedIndexChanging="lv_groups_SelectedIndexChanging">
                            <LayoutTemplate>
                                <table class="tbl-lv" style="width: 100%; margin-top: -15px; margin-bottom: -15px; padding:10px">
                                    <tr style="height:30px">
                                        <th style="width: 50%;">Product
                                        </th>
                                        <th style="width: 10%">Unit Size
                                        </th>
                                        <th style="width: 10%">Unit
                                        </th>
                                        <th style="width: 10%">Price (per unit)
                                        </th>
                                        <th style="width: 20%">QTY
                                        </th>
                                    </tr>
                                    <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
                                    <tr style="height:30px">
                                        <td colspan="5">
                                            <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lv_groups" PageSize="10">
                                                <Fields>
                                                    <asp:NextPreviousPagerField ShowLastPageButton="False" ShowNextPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" />
                                                    <asp:NumericPagerField ButtonType="Button" RenderNonBreakingSpacesBetweenControls="false" NumericButtonCssClass="btn btn-primary" CurrentPageLabelCssClass="btn disabled" NextPreviousButtonCssClass="btn" />
                                                    <asp:NextPreviousPagerField ShowFirstPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" />
                                                </Fields>
                                            </asp:DataPager>
                                        </td>
                                    </tr>
                                </table>
                            </LayoutTemplate>
                            <EmptyDataTemplate>
                                <table class="tbl-lv" style="width: 100%;">
                                    <tr>
                                        <th style="width: 50%;">Product
                                        </th>
                                        <th style="width: 10%">Unit Size
                                        </th>
                                        <th style="width: 10%">Unit
                                        </th>
                                        <th style="width: 10%">Price
                                        </th>
                                        <th style="width: 20%">QTY
                                        </th>
                                    </tr>
                                    <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
                                    <tr>
                                        <td colspan="5">
                                            <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lv_groups" PageSize="10">
                                                <Fields>
                                                    <asp:NextPreviousPagerField ShowLastPageButton="False" ShowNextPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" />
                                                    <asp:NumericPagerField ButtonType="Button" RenderNonBreakingSpacesBetweenControls="false" NumericButtonCssClass="btn btn-primary" CurrentPageLabelCssClass="btn disabled" NextPreviousButtonCssClass="btn" />
                                                    <asp:NextPreviousPagerField ShowFirstPageButton="False" ShowPreviousPageButton="False" ButtonType="Button" ButtonCssClass="btn btn-primary" RenderNonBreakingSpacesBetweenControls="false" />
                                                </Fields>
                                            </asp:DataPager>
                                        </td>
                                    </tr>
                                </table>
                            </EmptyDataTemplate>
                            <GroupTemplate>
                                <tr style="height:30px">
                                    <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
                                </tr>
                            </GroupTemplate>
                            <ItemTemplate>
                                <asp:HiddenField ID="HiddenField1" Value='<%# Eval("id") %>' runat="server" />
                                <td style="width: 50%">
                                    <%# Eval("product_description") %>
                                </td>
                                <td style="width: 10%">
                                    <%# Eval("unit_size", "{0:#### }") %>
                                </td>
                                <td style="width: 10%">
                                    <%# Eval("unit") %>
                                </td>
                                <td style="width: 10%">
                                    <%# Eval("price") %>
                                </td>
                                <td style="width: 20%">
                                    <asp:TextBox runat="server" ID="txtQty" ForeColor="Black" Width="80%" Text='<%# Eval("qty") %>'></asp:TextBox>
                                </td>
                            </ItemTemplate>
                        </asp:ListView>

请澄清你的问题。对于某些产品,您的CartTable似乎有多行,您希望将这些产品的数量相加,以便列表中每个产品只有一个条目。对吗?如果是这样的话,您如何分辨CartTable中的两行引用的是同一产品?
id
value?@O.Jones我想在ListView中输入数量,当ListView重新绑定以显示新数据时,必须将具有数量值的记录添加到列表视图中,但如果用户要返回页面,他们必须在其中添加数量,现在必须再次添加。
    {
        List<CartItems> items = new List<CartItems>();

        DataTable CartTable = pd.dt_products_qty(helpers.ConnectionString, product_group_id, order_id);

        if (CartTable != null && CartTable.Rows.Count > 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;
    }