zoukankan      html  css  js  c++  java
  • 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控件了,故怎么绑定数据呢?

  • 相关阅读:
    《Linux系统free命令的使用》学习笔记
    《postfix MAIL服务搭建(第一篇):》RHEL6
    RHEL(RedHat Enterprise Linux)5/6 ISO镜像下载
    《samba搭建win客户端和linux客户端的区别》
    《怎样实现通过shell脚本将用户踢出系统》
    《DDNS服务器的搭建和案例解决方法》
    《Usermod:user lee is currently logged in 家目录不能改变解决方法》
    你们看不懂为什么写这个博客吧
    JS几种数组遍历方式以及性能分析对比
    从概念到业务来看 To B 和 To C 产品区别在哪?
  • 原文地址:https://www.cnblogs.com/huaizuo/p/2108266.html
Copyright © 2011-2022 走看看