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++;
                    }
                }
            }
        }
Esempio n. 2
0
 protected void lkSave_Click(object sender, EventArgs e)
 {
     if (Page.IsPostBack)
     {
         DevMod.Models.MColor  mb = new DevMod.Models.MColor();
         DevMod.Classes.CColor cb = new DevMod.Classes.CColor();
         mb.Name = txtColorName.Text;
         if (cb.Save(mb) > 0)
         {
             SendMessageToPage("New Color Added");
         }
         else
         {
             SendMessageToPage("New Color was not Added");
         }
     }
 }
        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);
        }