displayproductcategory.aspx.cs

来自「是一个很好的电子商务系统,是用C#语言开发的,能够完成网上购物的功能」· CS 代码 · 共 70 行

CS
70
字号
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.Data.SqlClient;
public partial class DisplayProductcategory : System.Web.UI.Page
{   private static int categoryid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Request.QueryString["CID"]!="")
        {
            categoryid=Int32.Parse(Request.QueryString["CID"].ToString());
        }
        if(!Page.IsPostBack)
        {
            this.GetProductDataByCIDBind();
        }
    }
    private void GetProductDataByCIDBind()
    {
        ProductDB pdb=new ProductDB();
        SqlDataReader Sdr=pdb.GetProductDataByCategoryId(categoryid);
        this.DListProductByCategory.DataSource=Sdr;
        this.DListProductByCategory.DataBind();
        Sdr.Close();

    }
    public String GetProductDescription(String des)
    {
        if(des.Length>255)
        {
            return des.Substring(0,255)+"...";
        }
        else
        {
            return des;
        }
    }

    protected void DListProductByCategory_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (!User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/login_Register.aspx");
        }
        else
        {
            Shopcart shopcart = new Shopcart();
            shopcart.CustomerID = User.Identity.Name;
            shopcart.Quantity = 1;
            shopcart.ProductID = Int32.Parse(e.CommandArgument.ToString());
            ShopcarDB Sdb = new ShopcarDB();
            if (Sdb.GetShopcartItem(shopcart) > 0)
            {
                Sdb.UpdateShopCartFirst(shopcart, true);
            }
            else 
            {
                Sdb.AddShopCart(shopcart);
            }
        }
    }
}

⌨️ 快捷键说明

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