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

📄 index.aspx.cs

📁 这是我做的第一个网络购书中心asp.net网站!
💻 CS
字号:
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;

public partial class User_index : System.Web.UI.Page
{
    UserInfo ui = new UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {            
            refineBind();
            hotBind();
            hotDiscount();
        }
    }
    public void refineBind()
    {
        ui.DGBind(1, "refine", dlRefinement, true);
    }
    public void hotBind()
    {
        ui.DGBind(2, "hot", dlHot, true);
    }
    public void hotDiscount()
    {
        ui.DGBind(3, "Discount", dlDiscount, true);
    }
    protected void dlRefinement_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlRefinement.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlRefinement);

        }
    }
    protected void dlHot_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlHot.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlHot);
        }
    }
    protected void dlDiscount_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            Session["address"] = "";
            Session["address"] = "~/User/index.aspx";
            Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(dlDiscount.DataKeys[e.Item.ItemIndex].ToString()));
        }
        else if (e.CommandName == "buy")
        {
            addShopCart(e, dlDiscount);
        }
    }
    public void addShopCart(DataListCommandEventArgs e, DataList dlName)
    {
        if (Session["UID"] != null)
        {
            SaveGoodsClass sgc = getSaveGoodsClass(e, dlName);
            string userID = Session["UID"].ToString();
            ui.addShopCart(sgc.GoodsID, sgc.MemberPrice, userID);
            ui.MessageBox(Page, "添加成功");
        }
    }
    public SaveGoodsClass getSaveGoodsClass(DataListCommandEventArgs e, DataList dlName)
    {
        SaveGoodsClass goods = new SaveGoodsClass();
        goods.MemberPrice = Convert.ToDouble(e.CommandArgument.ToString());
        goods.GoodsID = dlName.DataKeys[e.Item.ItemIndex].ToString();
        return goods;
    }

   
}

⌨️ 快捷键说明

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