这是我的转发器
<asp:Repeater runat="server" ID="repBasket">
<ItemTemplate>
<li>
<a href="http://stylo.senseithemes.com/?product=flying-ninja">
<img width="100" height="130" src="http://stylo.senseithemes.com/wp-content/uploads/2013/06/poster_2_up-100x130.jpg" class="attachment-shop_thumbnail wp-post-image" alt="poster_2_up">
<%#Eval("ProductName") %>
</a>
<span class="quantity">
Quantity: <%#Eval("Quantity")%> x
<span class="price">
<span class="amount"><%#Eval("ProductPrice") %></span>
</span>
</span>
<div class="product-remove">
<a href="http://stylo.senseithemes.com/?page_id=16&remove_item=7cbbc409ec990f19c78c75bd1e06f215&_n=294a49ca25" class="btn-remove" title="Remove this item">×</a>
</div>
</li>
</ItemTemplate>
这是我按会话ID获取产品的代码
using (DermabonEntities db = new DermabonEntities())
{
var q = (from d in db.Basket
where d.UserId == sessionId
select d).ToList();
repBasket.DataSource = q;
repBasket.DataBind();
int UrunAdet = (from d in db.Basket
where d.UserId == sessionId
select d).Count();
Label.Text = UrunAdet.ToString();
}
我需要在转发器中总结ProductPrice如何总结它?
答案 0 :(得分:1)
在查询结束时,您可以使用以下代码计算总数:
TotalPrice = q.Aggregate(0D, (runningTotal, next) => runningTotal + (next.Quantity * next.ProductPrice));
您可以将此值设置为公共或受保护的属性,以便在您的网络表单上显示。
public double TotalPrice { get { return Convert.ToDouble(ViewState["TotalPrice"]); } set { ViewState["TotalPrice"] = value; } }