protected void gvDistrict_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { TransactionResult result; // Get the selected row's District id int districtIDToDelete = Convert.ToInt32(gvDistrict.DataKeys[e.RowIndex].Value); // Delete the selected District _currentDistrict = new District(); _currentDistrict.DistrictID = districtIDToDelete; _currentDistrict.ScreenMode = ScreenMode.Delete; result = _currentDistrict.Commit(); // Display the status of the delete System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script>alert('" + result.Message.ToString() + ".');"); sb.Append("</script>"); ScriptManager.RegisterStartupScript(this.Page, typeof(string), "MyScript", sb.ToString(), false); // If successfully deleted if (result.Status == TransactionStatus.Success) { ddlDistrictStates_SelectedIndexChanged(sender, e); tcntAllCSCTabs.ActiveTab = tpnlDistrict; } } catch (Exception ex) { ErrorLog.LogErrorMessageToDB("Countries.aspx", "", "gvDistrict_RowDeleting", ex.Message.ToString(), new ECGroupConnection()); throw; } }
protected void btnDistrictSave_Click(object sender, ImageClickEventArgs e) { try { // Create a new District Object _currentDistrict = new District(); // Set whether Add / Edit if (txtDistrictID.Text.ToString() != "0") _currentDistrict.AddEditOption = 1; else _currentDistrict.AddEditOption = 0; // Assign values to the District Object _currentDistrict.StateID = Convert.ToInt32(ddlDistrictState.SelectedValue.ToString()); _currentDistrict.DistrictID = Convert.ToInt32(txtDistrictID.Text.ToString()); _currentDistrict.DistrictDescription = txtDistrict.Text.ToString(); // Add / Edit the District TransactionResult result; _currentDistrict.ScreenMode = ScreenMode.Add; result = _currentDistrict.Commit(); // Display the Status - Whether successfully saved or not System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script>alert('" + result.Message.ToString() + ".');"); sb.Append("</script>"); ScriptManager.RegisterStartupScript(this.Page, typeof(string), "MyScript", sb.ToString(), false); // If successful if (result.Status == TransactionStatus.Success) { ddlDistrictStates_SelectedIndexChanged(sender, e); txtDistrictID.Text = ""; txtDistrict.Text = ""; tcntAllCSCTabs.ActiveTab = tpnlDistrict; } } catch (Exception ex) { ErrorLog.LogErrorMessageToDB("Countries.aspx", "", "btnDistrictSave_Click", ex.Message.ToString(), new ECGroupConnection()); throw; } }