打印本文 打印本文 关闭窗口 关闭窗口
[ASP.NET开发系列] 购物推车程序开发——调用购物车类
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4081  更新时间:2009/4/23 10:36:02  文章录入:mintao  责任编辑:mintao
        <asp:BoundColumn HeaderText="  " DataField="Price"

             DataFormatString="{0:c}" headerStyle-HorizontalAlign="center"

             ItemStyle-HorizontalAlign="right"/>

        <asp:BoundColumn HeaderText="数量" DataField="Quantity"

             headerStyle-HorizontalAlign="center"

             ItemStyle-HorizontalAlign="center"/> 

        <asp:ButtonColumn HeaderText="删除" Text="删除"

             headerStyle-HorizontalAlign="center"

             ItemStyle-HorizontalAlign="center" CommandName="DelFromCart"/>

       </columns>

        <HeaderStyle BackColor="teal" ForeColor="white" Font-Bold="true"/>

        <ItemStyle BackColor="white" ForeColor="darkblue"/>

        <AlternatingItemStyle BackColor="beige" ForeColor="darkblue"/>

        </asp:DataGrid>

    </center>

    <h3><asp:Label ID="Total" runat="server"/></h3>

    </form>

 </body>

</html>

 

<script Language="C#" runat="server">

  void Page_Load(Object sender,EventArgs e){

    ShoppingCart cart=(ShoppingCart)Session["MyShoppingCart"]; //创建实例

    if(cart !=null){

      MyDataGrid.DataSource=cart.Orders;

      MyDataGrid.DataBind();

      Total.Text=String.Format("合计:{0:c}",cart.TotalCost);

    }

  }

  void OnItemCommand(Object sender,DataGridCommandEventArgs e){

    if(e.CommandName=="DelFromCart"){

      ShoppingCart cart=(ShoppingCart)Session["MyShoppingCart"];

      if(cart != null){

         cart.DeleteItem(e.Item.Cells[0].Text);

         MyDataGrid.DataBind();

         Total.Text=String.Format("合计:{0:c}",cart.TotalCost);

      }

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口