我的页面左上角有一个购物车图标,我正在使用模板,它有一个功能鼠标悬停在该图标上,它显示了订购的项目列表。我想在同一个框中显示项目列表。我正在使用cookies,我通过breakpont检查我得到了cookie中的所有值。 下面是框的aspx代码:
<div class="navbar-ecommerce pull-right"><a href="#" class="link-cart"><i class="icon-cart"></i> <span class="badge">39</span></a>
<div class="cart-list">
<ul>
<li>
<%--<asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand" >--%>
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound" >
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<a href="#" class="cart-img"><img alt="" src=" images/ecommerce/products/hoodie_4_front-150x150.jpg"></a>
<p><a href="#"><%#Eval("ItemName") %></a> <span class="quantity">1 x <span class="amount"><%#Eval("Rate") %></span></span></p>
<a class="remove fa fa-times" href="#"></a>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</li>
</ul>
<div class="total"><strong>Subtotal:</strong> <span class="amount">$ 2,380.00</span></div>
<div class="buttons">
<a href="#" class="btn btn-default pull-left">View Cart</a>
<a href="#" class="btn btn-primary pull-right">Checkout</a>
</div>
</div>
</div>
我不确定要采取哪个事件,所以我采用OnItemCommand
和OnItemBound
没有一个触发后面的代码。
我的守则背后:
protected void Repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ItemName"), new DataColumn("Category"), new DataColumn("Rate") });
if (Request.Cookies["cart"] != null)
{
cookies = Convert.ToString(Request.Cookies["cart"].Value);
string[] arrorder = cookies.Split('|');
for (int i = 0; i < arrorder.Length; i++)
{
order = Convert.ToString(arrorder[i].ToString());
string[] arritem = order.Split(',');
for (int j = 0; j < arritem.Length; j++)
{
fields[j] = arritem[j].ToString();
}
dt.Rows.Add(fields[0].ToString(), fields[1].ToString(), fields[2].ToString());
}
}
Repeater2.DataSource = dt;
Repeater2.DataBind();
}
为protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
因此,请帮助触发哪个事件以使列表显示在框中。如果有任何替代方式,请让我也一样。感谢