Ejemplo n.º 1
0
    protected void Page_Init(object sender, EventArgs e)
    {
        // 宣告WHERE子句的IN條件
        //  string Converted_string = HttpUtility.UrlEncode("商品編號");
        //  string where = "WHERE [Converted_string] IN (";

        string where = "WHERE [商品編號] IN (";

        bool isFirst = true;

        // 取出所有Cookie
        foreach (string ProductItem in Request.Cookies)
        {
            // 是否是購物車的Cookie
            if (ProductItem.StartsWith("CUST E-Commerce"))
            {
                if (isFirst) // 第1次
                {
                    where     += "'" + Request.Cookies[ProductItem]["ID"] + "'";
                    Order_List = "CUST E-Commerce";
                    isFirst    = false;
                }
                else
                {
                    where += ", '" + Request.Cookies[ProductItem]["ID"] + "'";
                }
                hasItem = true;
            }
        }
        where += ")"; // 完成WHERE子句
        // 更改資料來源控制項的SELECT指令
        if (hasItem)
        {
            SqlDataSource1.SelectCommand += where;
        }

        else
        {
            SqlDataSource1.SelectCommand += "WHERE [商品編號] IN ('0000')";
        }
    }