complexprofile.aspx.cs

来自「asp。net 2.0宝典一书源码 全书源码给大家共享」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

public partial class ComplexProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindShoppingCart();
    }

    void BindShoppingCart()
    {
        if (Profile.ShoppingCart != null)
        {
            CartGrid.DataSource = Profile.ShoppingCart.CartItems;
            CartGrid.DataBind();
            lblTotal.Text = Profile.ShoppingCart.Total.ToString("c");
        }
    }

    protected void AddCartItem(Object s, EventArgs e)
    {
        GridViewRow row = ProductGrid.SelectedRow;

        int ID = (int)ProductGrid.SelectedDataKey.Value;
        String Name = row.Cells[1].Text;
        decimal Price = Decimal.Parse(row.Cells[2].Text,NumberStyles.Currency);

        if (Profile.ShoppingCart == null)
            Profile.ShoppingCart = new ShoppingCart();

        Profile.ShoppingCart.AddItem(ID, Name, Price);
        BindShoppingCart();
    }

    protected void RemoveCartItem(Object s, EventArgs e)
    {
        int ID = (int)CartGrid.SelectedDataKey.Value;
        Profile.ShoppingCart.RemoveItem(ID);
        BindShoppingCart();
    }
}

⌨️ 快捷键说明

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