⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoppingcart.ascx.cs

📁 ASP.NET2.0(C#篇)经典教程的源码...本源码很好的实现了购物车....编码规范和类的设计具有很好的借鉴性!
💻 CS
字号:
using System;
using System.Web.UI.WebControls;
using Wrox.Commerce;

partial class ShoppingCartControl : System.Web.UI.UserControl
{
  void Page_Load( object sender,  System.EventArgs e)
  {
    if (Profile.Cart == null)
      return;

    if (!Page.IsPostBack)
      BindGrid();

    if (Profile.Cart.Items.Count == 0)
    {
      TotalLabel.Visible = false;
      DiscountPanel.Visible = false;
    }
  }

  private void BindGrid()
  {
    // bind to the items in the cart
    CartGrid.DataSource = Profile.Cart.Items;
    DataBind();

    // TODO: sort out alignment
    if (Context.User.IsInRole("FanClubMember"))
    {
      SubTotalLabel.Text = string.Format("Sub-Total:{0,35:C}", Profile.Cart.SubTotal);
      MemberDiscount.Text = string.Format("Member Discount:{0:C}", Profile.Cart.MemberDiscount);
      DiscountPanel.Visible = true;
    }

    TotalLabel.Text = string.Format("Total:{0,19:C}", Profile.Cart.Total);
  }

  protected void CartGrid_RowEditing( object sender,  System.Web.UI.WebControls.GridViewEditEventArgs e)
  {
    CartGrid.EditIndex = e.NewEditIndex;
    BindGrid();
  }

  protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
  {
    TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0];
    int Quantity = Convert.ToInt32(QuantityTextBox.Text);

    if (Quantity == 0)
      Profile.Cart.Items.RemoveAt(e.RowIndex);
    else
      Profile.Cart.Items[e.RowIndex].Quantity = Quantity;

    CartGrid.EditIndex = -1;
    BindGrid();
  }

  protected void CartGrid_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
  {
    CartGrid.EditIndex = -1;
    BindGrid();
  }

  protected void CartGrid_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
  {
    Profile.Cart.Items.RemoveAt(e.RowIndex);
    BindGrid();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -