}//end add new skill protected void gvDeleteSkills_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "gvCommandDelete") { expertObj = (Expert)Session["expertProfileObj"]; int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvDeleteSkills.Rows[index]; string s = selectedRow.Cells[0].Text;//get skill name from selected row to be deleted. int count = 0;//test counter if no matches were found in forEach loop foreach (Tuple<int, String> skill in expertObj.AllExpertSkills) { if (skill.Item2.Equals(s, StringComparison.OrdinalIgnoreCase)) { count++;//found something int result = DbMethods.DeleteExpertSkill(expertObj.tuID, skill.Item1); if (result != -1) { lblGvDeleteTest.Text = "Skill has been deleted."; sm.storeExpertDataInSession();//now get the whole expert object FillControls(); } else lblGvDeleteTest.Text = "Unable to restore file. DataBase error. Please try again."; } if (count == 0) lblGvDeleteTest.Text = "could not find skill name in local DataSet. :("; } }//end Delete Skill Row Command }//end gvDeleteSkills_RowCommand
}//end fill controls protected void btnDeleteSkill_Click(object sender, EventArgs e) { List<int> skillIdList = new List<int>(); foreach (GridViewRow row in gvDeleteSkills.Rows) { if (row.RowType == DataControlRowType.DataRow) { CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox); if (chkRow.Checked) { skillIdList.Add(Convert.ToInt32(row.Cells[2])); } } } foreach (var sId in skillIdList) { int result = DbMethods.DeleteExpertSkill(studentObj.tuid, sId);//passing a long string of SkillIds into the method if (result != -1) lblDeleteTest.Text = "Success! New Skill was added to Skills and Expert_Skills Tables."; else lblDeleteTest.Text = "Error: Process did not execute successfully. :("; } //string idString = string.Join(",", skillIdList.Select(n => n.ToString()).ToArray()); }//end delete button