示例#1
0
        protected void gvSubCategory_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DropDownList ddl = null;

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                ddl = e.Row.FindControl("ddlMainCategory") as DropDownList;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ddl = e.Row.FindControl("ddlMainCategoryinner") as DropDownList;
            }
            if (ddl != null)
            {
                using (MasterCategoryRepository repository = new MasterCategoryRepository())
                {
                    var mainCategory = repository.GetList(0).OrderBy(r => r.Name).ToList();
                    if (mainCategory != null)
                    {
                        ddl.DataSource     = mainCategory;
                        ddl.DataTextField  = "Name";
                        ddl.DataValueField = "MainCategoryId";
                        ddl.DataBind();
                        ddl.Items.Insert(0, new ListItem("-- Select Category --", "0"));
                    }
                }
            }
        }
示例#2
0
        protected void gvMainCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int mainCategoryId = Convert.ToInt32(((Label)gvMainCategory.Rows[e.RowIndex].FindControl("lblCategoryId")).Text);

            using (MasterCategoryRepository repository = new MasterCategoryRepository())
            {
                repository.Delete(mainCategoryId);
            }
            BindMasterCategory();
        }
示例#3
0
        protected void lnkRemove_Click(object sender, EventArgs e)
        {
            LinkButton lnkRemove = (LinkButton)sender;
            int        Id        = Convert.ToInt32(lnkRemove.CommandArgument);

            using (MasterCategoryRepository repository = new MasterCategoryRepository())
            {
                repository.Delete(Id);
            }
            BindMasterCategory();
        }
示例#4
0
 private void BindMasterCategory()
 {
     using (MasterCategoryRepository repository = new MasterCategoryRepository())
     {
         List <MainCategoryMaster> mainCategory;
         mainCategory = repository.GetList(0).ToList();
         if (mainCategory.Count() > 0)
         {
             gvMainCategory.DataSource = mainCategory;
         }
         gvMainCategory.DataBind();
     }
 }
示例#5
0
        protected void btnAddMainCategory_Click(object sender, EventArgs e)
        {
            string name = ((TextBox)gvMainCategory.FooterRow.FindControl("txtAddCategory")).Text;

            using (MasterCategoryRepository repository = new MasterCategoryRepository())
            {
                MainCategoryMaster newMaster = new MainCategoryMaster
                {
                    Name = name,
                };

                repository.Add(newMaster);
            }
            BindMasterCategory();
        }
示例#6
0
        protected void gvMainCategory_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int    mainCategoryId = Convert.ToInt32(((Label)gvMainCategory.Rows[e.RowIndex].FindControl("lblCategoryId")).Text);
            string name           = ((TextBox)gvMainCategory.Rows[e.RowIndex].FindControl("txtCategory")).Text;

            using (MasterCategoryRepository repository = new MasterCategoryRepository())
            {
                var main = repository.Get(mainCategoryId);
                if (main != null)
                {
                    main.Name = name;
                    repository.Update();
                }
            }
            gvMainCategory.EditIndex = -1;
            BindMasterCategory();
        }
        private void BindMainCategories()
        {
            List <MainCategoryMaster> mainList;

            using (MasterCategoryRepository mainRepo = new MasterCategoryRepository())
                mainList = mainRepo.GetList(0).ToList();

            if (mainList.Count > 0)
            {
                ddlMain.DataSource     = mainList;
                ddlMain.DataTextField  = "Name";
                ddlMain.DataValueField = "MainCategoryId";
                mainCatId = mainList.Select(r => r.MainCategoryId).First();
                BindSubCategories();
            }

            ddlMain.DataBind();
            ddlMain.Items.Insert(0, new ListItem("Select Main Category", "0"));
        }