Member 14886708 Ответов: 0

Как отобразить разные значения в разных ячейках с одинаковыми полями ASP.NET C# gridview


Здравствуйте Разработчики,
В настоящее время я работаю над сайтом онлайн-покупок, на котором я хочу отобразить каждую ячейку, в которой должны быть разные продукты, но когда я использую методы ItemTemplates и OnRowDataBound, он показывает мне одни и те же продукты в одной строке, я добавил три столбца в GridView, но каждый столбец показывает мне одно и то же значение в соответствии с идентификатором строки. для определения, каждая клетка поставляется с различными значениями

Что я уже пробовал:

<asp:GridView ID="dgvProducts" runat="server" CssClass="table-products" OnRowCommand="dgvProducts_RowCommand"  AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false" BorderStyle="None" OnRowDataBound="dgvProducts_RowDataBound" RepeatDirection="Horizontal">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <div class="product-middle">
                                            <div class="registration-middle">
                                                
                                                <div class="product-middle-main">
                                                    <div class="product-middle-img">
                                                        <asp:Label ID="lblPID" Visible="false" Text='<%#Eval("ProductID") %>' runat="server" />
                                                        <img id="imgItem" src='<%#Eval("ProductImagePath") %>' style="border-radius: 15px;">
                                                        <asp:Label ID="lblPName"  CssClass="product-title-main" style=""  Text='<%#Eval("ProductName") %>' runat="server" /></div>
                                                        <div class="product-middle-select">
                                                            <asp:DropDownList AutoPostBack="true" CssClass="custom-select" runat="server" ID="ddlPackaging" OnSelectedIndexChanged="ddlPackaging_SelectedIndexChanged">
                                                            </asp:DropDownList>
                                                            <div class="number">
                                                                <asp:Button Text="-" CssClass="number-left" runat="server" ID="btnRemoveProduct" CommandName="RemoveItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnRemoveProduct_Click" />

                                                                <asp:Label CssClass="number-middle" ID="lblQtyAndRate" runat="server" Text="0 / Rs. 0.00"></asp:Label>

                                                                <asp:Button Text="+" CssClass="number-right" runat="server" ID="btnAddProduct" CommandName="AddItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnAddProduct_Click" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                
                                            </div>
                                        </div>
                                        
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnAddProduct" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnRemoveProduct" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="ddlPackaging" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
                                    </Triggers>
                                </asp:UpdatePanel>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <div class="product-middle">
                                            <div class="registration-middle">
                                                <div class="">
                                                <div class="product-middle-main">
                                                    <div class="product-middle-img">
                                                        <asp:Label ID="lblPID1" Visible="false" Text='<%#Eval("ProductID") %>' runat="server" />
                                                        
                                                        <img id="imgItem1" src='<%#Eval("ProductImagePath") %>' style="border-radius: 15px;">
                                                        <asp:Label ID="lblPName1"  CssClass="product-title-main" style=""  Text='<%#Eval("ProductName") %>' runat="server" /></div>
                                                        <div class="product-middle-select">
                                                            <asp:DropDownList AutoPostBack="true" CssClass="custom-select" runat="server" ID="ddlPackaging1" OnSelectedIndexChanged="ddlPackaging_SelectedIndexChanged">
                                                            </asp:DropDownList>
                                                            <div class="number">
                                                                <asp:Button Text="-" CssClass="number-left" runat="server" ID="btnRemoveProduct1" CommandName="RemoveItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnRemoveProduct_Click" />

                                                                <asp:Label CssClass="number-middle" ID="lblQtyAndRate1" runat="server" Text="0 / Rs. 0.00"></asp:Label>

                                                                <asp:Button Text="+" CssClass="number-right" runat="server" ID="btnAddProduct1" CommandName="AddItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnAddProduct_Click" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnAddProduct1" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnRemoveProduct1" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="ddlPackaging1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
                                    </Triggers>
                                </asp:UpdatePanel>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <div class="product-middle">
                                            <div class="registration-middle">
                                                <div class="">
                                                <div class="product-middle-main">
                                                    <div class="product-middle-img">
                                                        <asp:Label ID="lblPID2" Visible="false" Text='<%#Eval("ProductID") %>' runat="server" />

                                                        <img id="imgItem2" src='<%#Eval("ProductImagePath") %>' style="border-radius: 15px;">
                                                        <asp:Label ID="lblPName2"  CssClass="product-title-main" style=""  Text='<%#Eval("ProductName") %>' runat="server" /></div>
                                                        <div class="product-middle-select">
                                                            <asp:DropDownList AutoPostBack="true" CssClass="custom-select" runat="server" ID="ddlPackaging2" OnSelectedIndexChanged="ddlPackaging_SelectedIndexChanged">
                                                            </asp:DropDownList>
                                                            <div class="number">
                                                                <asp:Button Text="-" CssClass="number-left" runat="server" ID="btnRemoveProduct2" CommandName="RemoveItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnRemoveProduct_Click" />

                                                                <asp:Label CssClass="number-middle" ID="lblQtyAndRate2" runat="server" Text="0 / Rs. 0.00"></asp:Label>

                                                                <asp:Button Text="+" CssClass="number-right" runat="server" ID="btnAddProduct2" CommandName="AddItem" CommandArgument='<%#Eval("ProductID") %>' OnClick="btnAddProduct_Click" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnAddProduct2" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnRemoveProduct2" EventName="Click" />
                                    </Triggers>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="ddlPackaging2" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
                                    </Triggers>
                                </asp:UpdatePanel>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                    </Columns>
                </asp:GridView>

0 Ответов