/// <summary> /// Handles the DeleteCommand event of the grdMain control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdMain_DeleteCommand(object source, DataGridCommandEventArgs e) { if (mft != null) { MetaEnum.RemoveItem(mft, int.Parse(e.CommandArgument.ToString())); } BindGrid(GetDataTable()); }
protected void grdMain_DeleteCommand(object source, DataGridCommandEventArgs e) { if (ViewState[this.ClientID + "_TypeName"] == null) { return; } MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[ViewState[this.ClientID + "_TypeName"].ToString()]; if (mft != null) { MetaEnum.RemoveItem(mft, int.Parse(e.CommandArgument.ToString())); } else if (ViewState[this.ClientID + "_DataSource"] != null) { DataTable dt = ((DataTable)ViewState[this.ClientID + "_DataSource"]).Copy(); DataRow drDelete = null; foreach (DataRow dr in dt.Rows) { if (dr["Id"].ToString() == e.CommandArgument.ToString()) { drDelete = dr; break; } } //remove ordering foreach (DataRow dr in dt.Rows) { if ((int)dr["OrderId"] > (int)drDelete["OrderId"]) { dr["OrderId"] = (int)dr["OrderId"] - 1; } } if (drDelete != null) { dt.Rows.Remove(drDelete); } ViewState[this.ClientID + "_DataSource"] = dt; } BindGrid(GetDataTable()); }
private void dg_delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string dictionaryName = ddDictionaries.SelectedItem.Value; if (dictionaryName == ListManager.ListTypeEnumName) { MetaFieldType mft = Mediachase.Ibn.Core.MetaDataWrapper.GetEnumByName(dictionaryName); if (mft != null) { MetaEnum.RemoveItem(mft, int.Parse(e.CommandArgument.ToString())); } dgEnum.EditItemIndex = -1; } else { int ItemID = int.Parse(e.Item.Cells[0].Text); DictionaryTypes dic = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), dictionaryName); Dictionaries.DeleteItem(ItemID, dic); dgDic.EditItemIndex = -1; } BindDG(); }
protected void grdMain_DeleteCommand(object source, DataGridCommandEventArgs e) { if (ViewState[this.ClientID + "_TypeName"] == null) { return; } MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[ViewState[this.ClientID + "_TypeName"].ToString()]; if (mft != null) { //exists meta enum type MetaEnum.RemoveItem(mft, int.Parse(e.CommandArgument.ToString())); //update default values string sDef = String.Empty; if (ViewState[this.ClientID + "_IsDefaultId"] != null) { sDef = ViewState[this.ClientID + "_IsDefaultId"].ToString(); } string[] mas = sDef.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); List <string> lst = new List <string>(mas); if (lst.Contains(e.CommandArgument.ToString())) { lst.Remove(e.CommandArgument.ToString()); ViewState[this.ClientID + "_IsDefaultId"] = String.Join(",", lst.ToArray()); } } else if (ViewState[this.ClientID + "_DataSource"] != null) { //new meta enum type DataTable dt = ((DataTable)ViewState[this.ClientID + "_DataSource"]).Copy(); DataRow drDelete = null; foreach (DataRow dr in dt.Rows) { if (dr["Id"].ToString() == e.CommandArgument.ToString()) { drDelete = dr; break; } } //remove ordering foreach (DataRow dr in dt.Rows) { if ((int)dr["OrderId"] > (int)drDelete["OrderId"]) { dr["OrderId"] = (int)dr["OrderId"] - 1; } } if (drDelete != null) { dt.Rows.Remove(drDelete); } ViewState[this.ClientID + "_DataSource"] = dt; } BindGrid(GetDataTable()); }