protected void btSave_Click(object sender, EventArgs e) { StyleGuide.API api = new StyleGuide.API(); try { foreach (GridViewRow r in this.gvCatTypeList.Rows) { string Changed = getPostedValue(r, "hfChanged"); string tbId = getPostedValue(r, "tbID"); if (Changed == "1" || tbId == "-1") { string tbType = getPostedValue(r, "tbType"); StyleGuide.SgCategories.CategoryType type; if (tbId == "-1") { type = new StyleGuide.SgCategories.CategoryType(); } else { type = api.getCategoryTypeByID(Convert.ToInt64(tbId)); } if (type != null) { type.ID = Convert.ToInt64(tbId); type.Type = tbType; api.SaveCategoryType(type); ShowMessage("Category Type saved"); } else { throw new Exception("Category Type ID not found."); } } } Refresh(api); } catch (Exception ex) { ShowErrorMessage("Error on Save(). " + ex.Message); } finally { api.Dispose(); } }