protected void btNew_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                this.tbSearch.Text = "";
                btSave_Click(this.btSave, null);
                Refresh(api, UcPaging1.TotalPages);

                StyleGuide.PagingInfo pgInf = null;
                if (this.UcPaging1.CurrentPage > 0)
                {
                    pgInf = new StyleGuide.PagingInfo();
                    pgInf.RecordsPerPage = REC_PER_PAGE;
                    pgInf.CurrentPage    = this.UcPaging1.TotalPages;
                }

                StyleGuide.SgCategories.Categories cats = api.getAllCategories(pgInf);
                if (cats == null)
                {
                    cats = new StyleGuide.SgCategories.Categories();
                }

                StyleGuide.SgCategories.Category cat = new StyleGuide.SgCategories.Category();
                cat.ID   = -1;
                cat.Name = "New ";
                cats.Add(cat);

                this.gvCatList.DataSource = cats;
                this.gvCatList.DataBind();
                SetPaging(cats, true);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on CreateNew(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
        protected void btSave_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                Int32 PgIdx = UcPaging1.CurrentPage;
                foreach (GridViewRow r in this.gvCatList.Rows)
                {
                    string Changed = getPostedValue(r, "hfChanged");
                    string tbId    = getPostedValue(r, "tbID");
                    if (Changed == "1" || tbId == "-1")
                    {
                        string tbName     = getPostedValue(r, "tbName");
                        string ddlCatType = getPostedValue(r, "ddlCatTypes");
                        string tbNotes    = getPostedValue(r, "tbNotes");

                        StyleGuide.SgCategories.Category     cat;// = api.getCategoryByID(Convert.ToInt64(tbId));
                        StyleGuide.SgCategories.CategoryType catType = api.getCategoryTypeByID(Convert.ToInt64(ddlCatType));

                        if (tbId == "-1")
                        {
                            cat = new StyleGuide.SgCategories.Category();
                        }
                        else
                        {
                            cat = api.getCategoryByID(Convert.ToInt64(tbId));
                        }
                        if (cat != null)
                        {
                            cat.Name      = tbName;
                            cat.Type.ID   = catType.ID;
                            cat.Type.Type = catType.Type;
                            cat.Notes     = tbNotes;
                            cat.LMBY      = StyleGuideUI.App_Code.SgCommon.getLoggedUser();
                            api.SaveCategory(cat);
                            ShowMessage("Category saved");
                            if (tbId == "-1")
                            {
                                Refresh(api, UcPaging1.TotalPages);
                                PgIdx = UcPaging1.TotalPages;
                            }
                            else
                            {
                                PgIdx = UcPaging1.CurrentPage;
                            }
                        }
                        else
                        {
                            throw new Exception("Category ID not found.");
                        }
                    }
                }
                Refresh(api, PgIdx);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on Save(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }