private void SetPreviousData()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DropDownList ddlProducts =
                            (DropDownList)grdSales.Rows[rowIndex].Cells[0].FindControl("ddlProducts");

                        DropDownList ddlCategory =
                            (DropDownList)grdSales.Rows[rowIndex].Cells[1].FindControl("ddlCategory");

                        DropDownList ddlBrand =
                            (DropDownList)grdSales.Rows[rowIndex].Cells[2].FindControl("ddlBrand");

                        DropDownList ddlColor =
                            (DropDownList)grdSales.Rows[rowIndex].Cells[3].FindControl("ddlColor");

                        DropDownList ddlSubCategory =
                            (DropDownList)grdSales.Rows[rowIndex].Cells[4].FindControl("ddlSubCategory");
                        //Added these lines

                        ////Added these lines
                        DevMod.Models.MProducts    mp  = new DevMod.Models.MProducts();
                        DevMod.Models.MCategory    mc  = new DevMod.Models.MCategory();
                        DevMod.Models.MColor       mco = new DevMod.Models.MColor();
                        DevMod.Models.MSubCategory msb = new DevMod.Models.MSubCategory();
                        DevMod.Models.MBrand       mb  = new DevMod.Models.MBrand();
                        GetAll(mp, ddlProducts);
                        GetAll(mc, ddlCategory);
                        GetAll(mco, ddlColor);
                        GetAll(msb, ddlSubCategory);
                        GetAll(mb, ddlBrand);

                        ////****************

                        //****************

                        ddlProducts.SelectedValue = dt.Rows[i]["Products"].ToString();

                        ddlCategory.SelectedValue = dt.Rows[i]["Category"].ToString();

                        ddlBrand.SelectedValue = dt.Rows[i]["Brand"].ToString();

                        ddlColor.SelectedValue = dt.Rows[i]["Color"].ToString();

                        ddlSubCategory.SelectedValue = dt.Rows[i]["Sub Category"].ToString();
                        rowIndex++;
                    }
                }
            }
        }
Пример #2
0
 protected void lkSave_Click(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         try
         {
             if (fuImage1.HasFile && fuImage2.HasFile && fuImage3.HasFile)
             {
                 string filename1 = fuImage1.FileName;
                 string filename2 = fuImage2.FileName;
                 string filename3 = fuImage3.FileName;
                 fuImage1.PostedFile.SaveAs(Server.MapPath("~\\Images\\" + filename1.Trim()));
                 fuImage2.PostedFile.SaveAs(Server.MapPath("~\\Images\\" + filename2.Trim()));
                 fuImage3.PostedFile.SaveAs(Server.MapPath("~\\Images\\" + filename3.Trim()));
                 string path1                = "~\\Images\\" + filename1.Trim();
                 string path2                = "~\\Images\\" + filename2.Trim();
                 string path3                = "~\\Images\\" + filename3.Trim();
                 string Name                 = txtProductName.Text;
                 string Name2                = txtProductName2.Text;
                 string Name3                = txtProductName3.Text;
                 string Description          = txtDescription.Text;
                 string Price                = txtPrice.Text;
                 string Code                 = txtProductCode.Text;
                 DevMod.Classes.CProducts cp = new DevMod.Classes.CProducts();
                 DevMod.Models.MProducts  mp = new DevMod.Models.MProducts();
                 mp.Code        = Code;
                 mp.Name1       = Name;
                 mp.Name2       = Name2;
                 mp.Name3       = Name3;
                 mp.ImageUrl1   = path1;
                 mp.ImageUrl2   = path2;
                 mp.ImageUrl3   = path3;
                 mp.Description = Description;
                 mp.Price       = Price;
                 if (cp.Save(mp) > 0)
                 {
                     SendMessageToPage("Product Successfully Saved");
                 }
                 else
                 {
                     SendMessageToPage("Product was not Saved");
                 }
             }
             else
             {
                 SendMessageToPage("Please select images");
             }
         }
         catch
         {
         }
     }
 }
        private Dictionary <int, string> GetAll(DevMod.Models.MProducts model, DropDownList ddl)
        {
            Dictionary <int, string>       items     = new Dictionary <int, string>();
            List <DevMod.Models.MProducts> allBrands = new List <DevMod.Models.MProducts>();

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