protected void gvEntList_RowCommand(object sender, GridViewCommandEventArgs e) { string cmd = e.CommandName.ToLower(); StyleGuide.API api = new StyleGuide.API(); try { switch (cmd) { case "deleterow": { string entID = e.CommandArgument.ToString(); if (entID != "-1") { try { api.DropEntity(Convert.ToInt64(entID)); initHandler(); } catch (Exception ex) { if (ex.Message.Contains(" REFERENCE ")) { throw new Exception("Entity already in use, and cannot be deleted.<br /><br />" + ex.Message); } else { throw new Exception("Error on DeleteRow(). " + ex.Message); } } } Refresh(api, UcPaging1.CurrentPage); break; } case "catnew": //Image Button { GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow); if (gvRow != null) { ImageButton btCatNew = (ImageButton)(e.CommandSource as Control); System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat"); DropDownList ddlEntCatList = (DropDownList)gvRow.FindControl("ddlEntCatList"); ddlEntCatList.DataSource = api.getAllCategories(null, true); ddlEntCatList.DataBind(); divAddNewCat.Visible = true; btCatNew.Visible = false; } break; } case "catadd": // Buton { string entID = e.CommandArgument.ToString(); if (entID != "-1") { try { GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow); if (gvRow != null) { ImageButton btCatNew = (ImageButton)gvRow.FindControl("btCatNew"); System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat"); DropDownList ddlEntCatList = (DropDownList)gvRow.FindControl("ddlEntCatList"); string catID = ddlEntCatList.SelectedItem.Value; api.AddCategoryToEntity(Convert.ToInt64(catID), Convert.ToInt64(entID)); StyleGuide.SgEntities.Entity ent = api.getEntityByID(Convert.ToInt64(entID)); if (ent != null) { ent.LMBY = StyleGuideUI.App_Code.SgCommon.getLoggedUser(); api.SaveEntity(ent); } divAddNewCat.Visible = false; btCatNew.Visible = true; } } catch (Exception ex) { throw new Exception("Error on AddCategoryToEntity(). " + ex.Message); } } Refresh(api, UcPaging1.CurrentPage); break; } case "cataddcancel": //Button { string entID = e.CommandArgument.ToString(); if (entID != "-1") { try { GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow); if (gvRow != null) { ImageButton btCatNew = (ImageButton)gvRow.FindControl("btCatNew"); System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat"); btCatNew.Visible = true; divAddNewCat.Visible = false; } } catch (Exception ex) { throw new Exception("Error on AddCategoryToEntity(). " + ex.Message); } } Refresh(api, UcPaging1.CurrentPage); break; } default: { break; } } } catch (Exception ex) { ShowErrorMessage(ex.Message); } finally { api.Dispose(); } }