![](/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.