web层的控件之三---CartList

这个应该是清单的控件的,他将会被放在CheckOut.aspx中,本来这个控件没有什么好讲的,但这边的实现功能出乎我意料:

<asp:WizardStep ID="wzdStep5" runat="server" AllowReturn="False" StepType="Complete"
Title
="Receipt">
<div class="checkOutLabel">
Thank you for your order!
<br /><br />
<PetShopControl:CartList ID="CartListOrdered" runat="server"/>
<br />

<p>
A total of
<strong>
<asp:Literal ID="ltlTotalComplete" runat="server"></asp:Literal></strong> is
being charged to your credit card, ending with
<strong>
<asp:Literal ID="ltlCreditCardComplete" runat="server"></asp:Literal></strong>.</p>
<p>
If you have any questions regarding this order, please contact our customer service
at anytime.
</p>
<p>
The .NET Pet Shop Team
</p>
</div>
</asp:WizardStep>

看上面CartList的ID是CartListOrdered,那么看下CheckOut.aspx.cs是怎么用这个控件的呢?

 1 ///<summary>
2 /// Process the order
3 ///</summary>
4 protectedvoid wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e) {
5 if (Profile.ShoppingCart.CartItems.Count >0) {//说明有宠物下单了
6 if (Profile.ShoppingCart.Count >0) {//我觉得这个多余吧
7
8 // display ordered items
9 //应该是显示清单吧 调用CartList.aspx.cs中的Bind函数
10 CartListOrdered.Bind(Profile.ShoppingCart.CartItems);
11
12 // display total and credit card information
13 ltlTotalComplete.Text = ltlTotal.Text;
14 ltlCreditCardComplete.Text = ltlCreditCard.Text;
15
16 // create order
17 OrderInfo order =new OrderInfo(int.MinValue, DateTime.Now, User.Identity.Name, GetCreditCardInfo(), billingForm.Address, shippingForm.Address, Profile.ShoppingCart.Total, Profile.ShoppingCart.GetOrderLineItems(), null);
18
19 // 调用BLL.Order
20 Order newOrder =new Order();
21 newOrder.Insert(order);
22
23 // destroy cart
24 Profile.ShoppingCart.Clear();
25 Profile.Save();
26 }
27 }
28 else {
29 lblMsg.Text ="<p><br>Can not process the order. Your cart is empty.</p><p class=SignUpLabel><a class=linkNewUser href=Default.aspx>Continue shopping</a></p>";
30 wzdCheckOut.Visible =false;
31 }
32 }

我当初在看这个CartList控件的时候就在想,他后台有个Bind函数,那么什么时候才会去调用呢?这个时候再这边就用到了。那么在CheckOut.aspx.cs直接设置这个Bind函数可以吗?答案不可以。说了那么就还没有吧这个函数给贴出来:

publicvoid Bind(ICollection<CartItemInfo> cart)
{
//ICollection是一种泛值类型 这里相当于IList,但我不知道怎么调用这个Bind函数
if (cart !=null) {
repOrdered.DataSource
= cart;
repOrdered.DataBind();
}

}

为什么不行呢?因为控件在CheckOut.aspx中并没有全部显示出来,所以也就没有了repeater控件了,故怎么绑定数据呢?

 

 

 

 

 

posted @ 2011-07-16 16:42  小霖2012  阅读(477)  评论(0编辑  收藏  举报