![](/img/trans.png)
[英]Getting Shopping cart quanitity counter to show product added right when selected to add
[英]how find which product is selected in asp:repeater because i want to add this selected product in shopping cart
我想為我的在線商店制作購物車。我為此使用 asp:repeater。我的問題是我不知道選擇了哪個產品,因為我不知道選擇了哪個產品 id。我使用 javascript 函數來做that.when 用戶點擊添加到購物車按鈕然后在 javascript 函數中,這個選定的 id 被添加到數組中,但我不知道產品 id。
設計文件
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<!-- add repeater -->
<a href="#">
<asp:Image ID="Image1" runat="server" class="card-img-top" ImageUrl='<%# Eval("imageUrl") %>' Style="height: 100px; width: 250px;" /></a>
<!--
<img class="card-img-top" src="http://placehold.it/700x400" alt=""></a>
-->
<div class="card-body">
<h4 class="card-title" runat="server">
<a href="#">
<asp:Label ID="nameMedicine" runat="server" Text='<%# Eval("name") %>' /></a>
<!--<a href="#"><%#Eval("name") %></a>-->
</h4>
<h5>price <%#Eval("price") %></h5>
<p class="card-text"><%#Eval("description") %></p>
</div>
<div class="card-footer">
<small class="text-muted">★ ★ ★ ★ ☆</small>
</div>
<asp:Button ID="addItems" OnClientClick="addToCart()" ClientIDMode="Predictable" runat="server" Text="Add To Cart" Style="color: white; background-color: #6dabe4;" />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
<script>
function addToCart() {
alert(document.getElementById("nameMedicine"));
}
</script>
您可以將您的產品/葯物 ID 作為參數發送給您的函數 addToCart。 請參閱以下內容:
<asp:Button ID="addItems" OnClientClick="addToCart(<%# Eval("ProductId") %>)" ClientIDMode="Predictable" runat="server" Text="Add To Cart" Style="color: white; background-color: #6dabe4;" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.