protected void Delete(object sender, EventArgs e) { for (int i = 0; i < GridView.Rows.Count; i++) { if (GridView.Rows[i].RowType == DataControlRowType.DataRow) { CheckBox chk = (CheckBox)GridView.Rows[i].Cells[0].FindControl("CheckBox") as CheckBox; if (chk.Checked) { int RecordID = (int)GridView.DataKeys[i].Value; if (_businesscode.GetRelationHospitalHasDoctors(Convert.ToInt32(GridView.DataKeys[i].Value)).Count != 0) //--Var { _businesscode.DeleteRelationHospitalHasDoctors(RecordID); //--Var } if (_businesscode.GetRelationHospitalHasProjects(Convert.ToInt32(GridView.DataKeys[i].Value)).Count != 0) //--Var { _businesscode.DeleteRelationHospitalHasProjects(RecordID); //--Var } _businesscode.DeleteDepartment(-1, string.Format("OR Hospital_ID = {0}", RecordID)); _businesscode.DeleteHospital(Convert.ToInt32(RecordID)); } } } Response.Redirect("../Site/HospitalPage.aspx"); }