protected void dlItem_ItemCommand(object sender, DataListCommandEventArgs e) { int attributeId = e.Item.ItemIndex > -1 ? (int)dlAttributes.DataKeys[e.Item.ItemIndex] : -1; TextBox txtAttributeName = e.Item.FindControl("txtAttributeName") as TextBox; TextBox txtDescription = e.Item.FindControl("txtDescription") as TextBox; DropDownList ddlAttributeValueType = e.Item.FindControl("ddlAttributeValueType") as DropDownList; Literal litAttributeName = e.Item.FindControl("litAttributeName") as Literal; bool success = false; ShowMessage(string.Empty); switch (e.CommandName) { case "Add": dlAttributes.EditItemIndex = -1; HtmlTableRow addNewContainer = e.Item.FindControl("addNewContainer") as HtmlTableRow; addNewContainer.Visible = true; txtAttributeName.Text = ""; txtDescription.Text = ""; ddlAttributeValueType.SelectedIndex = 0; ShowError(string.Empty); break; case "Insert": if (!ValidateAttributeEntry(e)) { txtAttributeName.Focus(); return; } ShowError(string.Empty); ObjectAttribute.SaveAttribute(txtAttributeName.Text.Trim(), txtDescription.Text.Trim()); ShowMessage(string.Format("Attribubute '{0}' successfully created.", txtAttributeName.Text.Trim())); dlAttributes.EditItemIndex = -1; PopulateAttributes(); break; case "Edit": dlAttributes.EditItemIndex = e.Item.ItemIndex; PopulateAttributes(); break; case "Update": if (!ValidateAttributeEntry(e)) { txtAttributeName.Focus(); return; } ShowError(string.Empty); // save attribute ObjectAttribute.SaveAttributeById(attributeId, txtAttributeName.Text.Trim(), txtDescription.Text.Trim(), ddlAttributeValueType.SelectedItem.Text); ShowMessage(string.Format("Attribubute '{0}' successfully updated.", txtAttributeName.Text.Trim())); dlAttributes.EditItemIndex = -1; PopulateAttributes(); break; case "Delete": success = true; try { ObjectAttribute.DeleteAttribute(litAttributeName.Text); } catch (Exception ex) { success = false; ShowError(string.Format("Errors encountered while deleting attribute '{0}' (possibly due associated values): <br/>" + ex.Message, litAttributeName.Text)); } if (success) { ShowMessage(string.Format("Attribute '{0}' successfully deleted.", litAttributeName.Text)); } PopulateAttributes(); break; case "Cancel": dlAttributes.EditItemIndex = -1; ShowError(string.Empty); PopulateAttributes(); mpePopup.Hide(); break; } }