protected void btNew_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         btSave_Click(this.btSave, null);
         StyleGuide.SgCategories.CategoryType type = new StyleGuide.SgCategories.CategoryType();
         type.ID   = -1;
         type.Type = "New ";
         StyleGuide.SgCategories.CategoryTypes types = api.getAllCategoryTypes();
         if (types == null)
         {
             types = new StyleGuide.SgCategories.CategoryTypes();
         }
         types.Add(type);
         this.gvCatTypeList.DataSource = types;
         this.gvCatTypeList.DataBind();
     }
     catch (Exception ex)
     {
         ShowErrorMessage("Error on CreateNew(). " + ex.Message);
     }
     finally
     {
         api.Dispose();
     }
 }
        protected void gvCatList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            bool borderleft = false;

            foreach (TableCell tc in e.Row.Cells)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    if (!borderleft)
                    {
                        tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                        borderleft             = true;
                    }
                    else
                    {
                        tc.Attributes["style"] = "border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                    }
                }
                else
                {
                    if (!borderleft)
                    {
                        tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;";
                        borderleft             = true;
                    }
                    else
                    {
                        tc.Attributes["style"] = "border-right:1px solid #c3cecc;";
                    }
                }
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddlCatTypes = (e.Row.FindControl("ddlCatTypes") as DropDownList);
                if (ddlCatTypes != null)
                {
                    try
                    {
                        StyleGuide.API api = new StyleGuide.API();
                        try
                        {
                            ddlCatTypes.DataSource     = api.getAllCategoryTypes(null, true);
                            ddlCatTypes.DataTextField  = "Type";
                            ddlCatTypes.DataValueField = "ID";
                            ddlCatTypes.DataBind();
                            ddlCatTypes.Style.Add("-webkit-appearance", "none");
                            StyleGuide.SgCategories.CategoryType catType = (StyleGuide.SgCategories.CategoryType)DataBinder.Eval(e.Row.DataItem, "Type");
                            if (catType != null)
                            {
                                int idx = _Library._Web._Common.FindDdlItemIndex(ddlCatTypes, catType.ID.ToString(), true);
                                ddlCatTypes.SelectedIndex = idx;
                            }
                            else
                            {
                                ddlCatTypes.Items.Insert(0, new ListItem("Please select", ""));
                            }

                            long catID = Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "ID"));
                            if (catID == -1)
                            {
                                (e.Row.FindControl("tbID") as TextBox).ForeColor             = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbName") as TextBox).ForeColor           = System.Drawing.Color.Red;
                                (e.Row.FindControl("ddlCatTypes") as DropDownList).ForeColor = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbNotes") as TextBox).ForeColor          = System.Drawing.Color.Red;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            api.Dispose();
                        }
                    }
                    catch (Exception) { }
                }
            }
        }
 public void Refresh(StyleGuide.API api)
 {
     this.gvCatTypeList.DataSource = api.getAllCategoryTypes();
     this.gvCatTypeList.DataBind();
 }