protected void gviewProductCategory_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Ref_ProductCategory prodCategory = new Ref_ProductCategory();

            prodCategory.CategoryID   = Convert.ToInt32((gviewProductCategory.Rows[e.RowIndex].FindControl("hdnCategoryID") as HiddenField).Value);
            prodCategory.CategoryName = (gviewProductCategory.Rows[e.RowIndex].FindControl("txtCategoryName") as TextBox).Text;
            prodCategory.Description  = (gviewProductCategory.Rows[e.RowIndex].FindControl("txtDescription") as TextBox).Text;
            prodCategory.ModifiedBy   = User.Identity.Name.ToString();

            Ref_ProductCategoryManager.Save(prodCategory);
            gviewProductCategory.EditIndex = -1;

            //enable the save button on the panel above after update
            lnkSaveProductCategory.Enabled  = true;
            lnkSaveProductCategory.CssClass = "linkStyle";

            PopulateGridview();



            //show the edit and delete column
            gviewProductCategory.Columns[3].Visible = true; //edit column
            gviewProductCategory.Columns[4].Visible = true; //delete column

            //hide the update and cancel column
            gviewProductCategory.Columns[5].Visible = false; //update column
            gviewProductCategory.Columns[6].Visible = false; //cancel column
        }
        protected void lnkSaveProductCategory_OnCommand(object sender, CommandEventArgs e)
        {
            //clear previous messages
            lblMessage.Text = "";

            Ref_ProductCategory newProdCategory = new Ref_ProductCategory();

            newProdCategory.CategoryName = (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Text.Trim().ToUpper();
            newProdCategory.Description  = (fviewProdCategory.FindControl("txtProductCategoryDescription") as TextBox).Text.Trim();
            newProdCategory.CreatedBy    = User.Identity.Name.ToString();

            //check if the category name already exist

            //get existing categories
            Ref_ProductCategoryList existingCategories = Ref_ProductCategoryManager.GetList();

            // find a match
            IEnumerable <Ref_ProductCategory> query =
                from cat in existingCategories
                where cat.CategoryName == newProdCategory.CategoryName
                select cat;

            // if there is no match, then proceed with add
            if (!query.Any())
            {
                //add the new product category
                Ref_ProductCategoryManager.Save(newProdCategory);
                //clear the inputs

                (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Text        = "";
                (fviewProdCategory.FindControl("txtProductCategoryDescription") as TextBox).Text = "";
            }
            else
            {
                lblMessage.Text      = "Category name" + newProdCategory.CategoryName + " already exist.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                (fviewProdCategory.FindControl("txtProductCategoryName") as TextBox).Focus();
            }



            PopulateGridview();

            gviewProductCategory.Focus();
        }