예제 #1
0
 protected void grdProducts_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         int          rowIndex  = e.Row.RowIndex;
         DropDownList ddlColors = (DropDownList)e.Row.FindControl("ddlColors");
         List <DevMod.Models.MColor> allColors =
             (List <DevMod.Models.MColor>)HttpContext.Current.Cache["allColors"];
         if ((List <DevMod.Models.MColor>)HttpContext.Current.Cache["allColors"] == null)
         {
             DevMod.Classes.CColor cc = new DevMod.Classes.CColor();
             allColors = cc.GetAll();
         }
         Dictionary <int, string> colorsDt = new Dictionary <int, string>();
         for (int i = 0; i < allColors.Count; i++)
         {
             colorsDt.Add(Convert.ToInt32(allColors[i].id), allColors[i].Name);
         }
         ddlColors.DataValueField = "Key";
         ddlColors.DataTextField  = "Value";
         ddlColors.DataSource     = colorsDt;
         ddlColors.DataBind();
         //for (int i = 0; i < ddlColors.Items.Count; i++)
         //{
         //    ddlColors.Items[i].Attributes.Add("style", "color:" + ddlColors.Items[i].Text);
         //}
     }
 }
예제 #2
0
        private void CacheData()
        {
            List <DevMod.Models.MCategory>          allCategories               = new List <DevMod.Models.MCategory>();
            List <DevMod.Models.MPrice>             allPrice                    = new List <DevMod.Models.MPrice>();
            List <DevMod.Models.MProductContainer>  allProductContainer         = new List <DevMod.Models.MProductContainer>();
            List <DevMod.Models.MSubCategory>       allSubCategories            = new List <DevMod.Models.MSubCategory>();
            List <DevMod.Models.MCategoryContainer> allCategoryContainer        = new List <DevMod.Models.MCategoryContainer>();
            List <DevMod.Models.MBrand>             allBrands                   = new List <DevMod.Models.MBrand>();
            List <DevMod.Models.MColor>             allColors                   = new List <DevMod.Models.MColor>();
            List <DevMod.Models.MCommon.MViewObjects.MViewProducts> allProducts = new List <DevMod.Models.MCommon.MViewObjects.MViewProducts>();

            DevMod.Classes.CSubCategory         msc = new DevMod.Classes.CSubCategory();
            DevMod.Classes.CCommon.CViewObjects cv  = new DevMod.Classes.CCommon.CViewObjects();
            DevMod.Classes.CCategory            mc  = new DevMod.Classes.CCategory();
            DevMod.Classes.CCategoryContainer   mcc = new DevMod.Classes.CCategoryContainer();
            DevMod.Classes.CPrice            cp     = new DevMod.Classes.CPrice();
            DevMod.Classes.CBrand            cb     = new DevMod.Classes.CBrand();
            DevMod.Classes.CColor            cc     = new DevMod.Classes.CColor();
            DevMod.Classes.CProductContainer cpc    = new DevMod.Classes.CProductContainer();
            allPrice             = cp.GetAll();
            allSubCategories     = msc.GetAll();
            allCategories        = mc.GetAll();
            allCategoryContainer = mcc.GetAll();
            allBrands            = cb.GetAll();
            allColors            = cc.GetAll();
            allProductContainer  = cpc.GetAll();
            allProducts          = cv.GetAllProducts();
            HttpContext.Current.Cache.Remove("allPrice");
            HttpContext.Current.Cache.Remove("allCategories");
            HttpContext.Current.Cache.Remove("allSubCategories");
            HttpContext.Current.Cache.Remove("allCategoryContainer");
            HttpContext.Current.Cache.Remove("allProductContainer");
            HttpContext.Current.Cache["allSubCategories"]     = allSubCategories;
            HttpContext.Current.Cache["allCategories"]        = allCategories;
            HttpContext.Current.Cache["allCategoryContainer"] = allCategoryContainer;
            HttpContext.Current.Cache["allPrice"]             = allPrice;
            HttpContext.Current.Cache["allBrands"]            = allBrands;
            HttpContext.Current.Cache["allColors"]            = allColors;
            HttpContext.Current.Cache["allProducts"]          = allProducts;
            HttpContext.Current.Cache["allProductContainer"]  = allProductContainer;
            BindCategoriesRepeater();
            BindPriceRanges();
            BindAllBrands();
            BindAllColors();
            BindItemsPerPageDll();
            BindAllProducts(0, itemsPerPage, allProducts);
            BindPagingRepeater(0, itemsPerPage, allProducts);
        }
        private Dictionary <int, string> GetAll(DevMod.Models.MColor model, DropDownList ddl)
        {
            Dictionary <int, string>    items     = new Dictionary <int, string>();
            List <DevMod.Models.MColor> allBrands = new List <DevMod.Models.MColor>();

            if (HttpContext.Current.Cache["allBrands"] != null)
            {
                allBrands = (List <DevMod.Models.MColor>)HttpContext.Current.Cache["allColors"];
            }
            else
            {
                DevMod.Classes.CColor cb = new DevMod.Classes.CColor();
                allBrands = cb.GetAll();
            }
            foreach (var item in allBrands)
            {
                items.Add(Convert.ToInt32(item.id), item.Name);
            }
            ddl.DataTextField  = "Value";
            ddl.DataValueField = "Key";
            ddl.DataSource     = items;
            ddl.DataBind();
            return(items);
        }