购物车asp.net c#

时间:2016-05-20 16:24:37

标签: c# asp.net shopping-cart

我有购物页面,但数量有问题,我不知道如何选择文本框的价值,这是我的代码。



<table class="table table-condensed">
					<thead>
						<tr class="cart_menu">
							<td class="image">Product</td>
                            <td><div class="col-md-1"></div> </td>
							<td class="description"></td>
							<td class="price">Price</td>
							<td class="quantity">Quantity</td>
							<td class="total">Total</td>
							<td><div class="col-md-1"></div></td>
						</tr>
					</thead>
					<tbody>
                        
                        <!-- begin Cart -->
                        <% for(int j=0;j<NoItems;j++)
                           {
                               Label8.Text = j.ToString();
                               view();%>
                        
						<tr>
                            <td style="display:block">
                                   <asp:Label ID="Label8" runat="server"></asp:Label></td>
							<td class="cart_product">                           
								<a href="#"><img src="/WebVenta/img/enrollable2.jpg" alt="" width="110"></a>                           
							</td> 
                            <td><div class="col-md-1"></div></td>
							<td class="cart_description">
                                
								<h4><a href="/WebVenta/Page/Producto.aspx">Persiana Enrollable</a></h4>
								<p><asp:Label ID="Label1" runat="server" Text=''></asp:Label></p>
							</td>
							<td class="cart_price">
								<p><asp:Label ID="Label2" runat="server" Text=""></asp:Label></p>
							</td>
							<td class="cart_quantity">
								<div class="cart_quantity_button">						
                                       <asp:TextBox ID="Cantidad" class="cart_quantity_input" runat="server" Width="50px"></asp:TextBox>				
								</div>
							</td>
							<td class="cart_total">
								<p class="cart_total_price"><asp:Label ID="Label3" runat="server" Text="Label" autocomplete="off" size="2"></asp:Label></p>
							</td>
							<td class="cart_delete">
								<a class="cart_quantity_delete" onclick="Borrar()" runat="server"><i class="fa fa-times"></i></a>     
							</td>
						</tr>
                        <% i++;
                           } %>

                        <!-- end -->

					</tbody>
				</table>


now in the behind code have this 

 public string[,] Carrito = new string[20, 13];
 NoItems = Convert.ToInt32(Session["NoItems"]);//its the number of differents items
 Carrito = (String[,])Session["Cart"];//its a array with all products


public void view()
{
    Label1.Text = (String)Carrito[i, 1] + "/" + (String)Carrito[i, 3] + "/" + (String)Carrito[i, 4] + "/" + (String)Carrito[i, 5] + "/" + (String)Carrito[i, 6] + "/" +
         (String)Carrito[i, 7] + "/" + (String)Carrito[i, 8] + "/" + (String)Carrito[i, 9] + "/" + (String)Carrito[i, 10];
    Label2.Text = "$" + (String)Carrito[i, 2];
    Label3.Text = "$" + (String)Carrito[i, 2];
    Cantidad.Text = (String)Carrito[i, 13];
}

public void comprar(object sender, EventArgs e)
{
    for (int a = 0; a < NoItems; a++)
    {
        
    }
}
&#13;
&#13;
&#13;

现在我的问题是如何保存产品的数量,

现在我不使用数据库,它在Sessions中的所有信息,数据库正在进行中。

任何想法?抱歉,我的英文。

1 个答案:

答案 0 :(得分:0)

您可以通过解析Cantidad

中的文字来阅读数量
int quantity = 0;
int.TryParse( Cantidad.Text, out quantity );

您还应该将Cantidad的class属性更改为CssClass