protected void lkSave_Click(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                DevMod.Models.MSubCategory  mb = new DevMod.Models.MSubCategory();
                DevMod.Classes.CSubCategory cb = new DevMod.Classes.CSubCategory();
                if (fuImage1.HasFile)
                {
                    string fileName1 = fuImage1.FileName;
                    fuImage1.PostedFile.SaveAs(Server.MapPath("~\\Images\\" + fileName1.Trim()));
                    string path1 = "~\\Images\\" + fileName1.Trim();
                    mb.ImageUrl = path1;
                    mb.Code     = txtSubCategoryCode.Text;
                    mb.Name     = txtSubCategoryName.Text;

                    if (cb.Save(mb) > 0)
                    {
                        SendMessageToPage("New Sub Category Added");
                    }
                    else
                    {
                        SendMessageToPage("New Sub Category was not Added");
                    }
                }
                else
                {
                    SendMessageToPage("Please select an image");
                }
            }
        }
        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++;
                    }
                }
            }
        }
        private Dictionary <int, string> GetAll(DevMod.Models.MSubCategory model, DropDownList ddl)
        {
            Dictionary <int, string>          items     = new Dictionary <int, string>();
            List <DevMod.Models.MSubCategory> allBrands = new List <DevMod.Models.MSubCategory>();

            if (HttpContext.Current.Cache["allBrands"] != null)
            {
                allBrands = (List <DevMod.Models.MSubCategory>)HttpContext.Current.Cache["allSubCategories"];
            }
            else
            {
                DevMod.Classes.CSubCategory cb = new DevMod.Classes.CSubCategory();
                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);
        }