protected void gridViewOrganisms_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName != "Page") { ProjectBLL projectBLL = new ProjectBLL(); Project project = projectBLL.GetProjectByProjectID(Convert.ToInt32(Page.RouteData.Values["project_id"])); OrganismBLL organismBLL = new OrganismBLL(); Organism organism = organismBLL.GetOrganismByOrganismID(Convert.ToInt32(e.CommandArgument)); Project_OrganismsBLL project_OrganismsBLL = new Project_OrganismsBLL(); Project_Organisms project_Organism = new Project_Organisms(); project_Organism.ProjectID = project.ProjectID; project_Organism.ProjectReference.EntityKey = project.EntityKey; project_Organism.OrganismID = organism.OrganismID; project_Organism.OrganismReference.EntityKey = organism.EntityKey; project_Organism.CreatedDate = DateTime.Now; project_Organism.EditedDate = DateTime.Now; project_OrganismsBLL.CreateNewProject_Organisms(project_Organism); Response.RedirectToRoute("organismsinproject", new { project_id = (Page.RouteData.Values["project_id"] as string) }); } }
protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e) { try { // Create a List to hold the OrganismID values to delete List <Int32> OrganismIDsToDelete = new List <Int32>(); // Iterate through the Organisms.Rows property foreach (GridViewRow row in gridViewCommonNames.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)(row.FindControl("chkCommonNameSelector")); if (cb != null && cb.Checked) { // Save the OrganismID value for deletion // First, get the OrganismID for the selected row Int32 OrganismID = (Int32)gridViewCommonNames.DataKeys[row.RowIndex].Value; OrganismBLL commonNameBLL = new OrganismBLL(); Eisk.BusinessEntities.Organism organism = commonNameBLL.GetOrganismByOrganismID(OrganismID); // Add it to the List... OrganismIDsToDelete.Add(OrganismID); // Add a confirmation message ltlMessage.Text += String.Format(MessageFormatter.GetFormattedSuccessMessage("Delete successful. Organism <b>{0}</b> has been deleted"), organism.CommonName.CommonNameDesc); } } //perform the actual delete new OrganismBLL().DeleteOrganisms(OrganismIDsToDelete); } catch (Exception ex) { ltlMessage.Text = ExceptionManager.DoLogAndGetFriendlyMessageForException(ex); } //binding the grid gridViewCommonNames.PageIndex = 0; gridViewCommonNames.DataBind(); }