protected void modalBtnSubmit_Command(object sender, CommandEventArgs e) { int roleId = Convert.ToInt32(modalDropDownRoles.SelectedItem.Value); RoleDepartmentAccess departmentAccess = new RoleDepartmentAccess(); for (int i = 0; i < modalGridViewDepartment.Rows.Count; i++) { CheckBox cb = (CheckBox)modalGridViewDepartment.Rows[i].FindControl("modalChkBoxSelect"); Label labelDepartmentId = (Label)modalGridViewDepartment.Rows[i].FindControl("modalLabelDepartmentId"); departmentAccess.DepartmentId = Convert.ToInt32(labelDepartmentId.Text); departmentAccess.RoleId = roleId; if (cb.Checked != true && labelDepartmentId.ToolTip != "ToolTip") //Delete { departmentAccess.Delete(Convert.ToInt32(labelDepartmentId.ToolTip)); } else if (cb.Checked == true && labelDepartmentId.ToolTip == "ToolTip") //Add { departmentAccess.Insert(departmentAccess); } else if (cb.Checked == true && labelDepartmentId.ToolTip != "ToolTip") //Update { departmentAccess.Id = Convert.ToInt32(labelDepartmentId.ToolTip); departmentAccess.Update(departmentAccess); } } InitializeGridRoles(); }