private void sbtDelete_Click(object sender, EventArgs e) { //List<int> selectedIDList = new List<int>(); int[] rowHandles = this.gvRoles.GetSelectedRows();//获取选中行号; if (rowHandles.Length == 0) { XtraMessageBox.Show("please select deleted rows!", "提示", MessageBoxButtons.OK); return; } if (DialogResult.OK == XtraMessageBox.Show("deleting these rows ?", "waring", MessageBoxButtons.OKCancel)) { List <RolesVM> selectedList = new List <RolesVM>(); foreach (var rowHandle in rowHandles) { ////获取选中行的ID //selectedIDList.Add(int.Parse(this.gvRoles.GetRowCellValue(rowHandle, "ID").ToString())); RolesVM vm = this.gvRoles.GetRow(rowHandle) as RolesVM; if (vm.Name.ToLower() == "admin") { XtraMessageBox.Show("can not delete role admin!", "提示", MessageBoxButtons.OK); return; } selectedList.Add(vm); } int res = _bll.DeleteRoles(selectedList.Select(p => p.ID).ToList()); if (res > 0) { XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK); this.teRoleName.Text = string.Empty; RequestGridData(); } else { XtraMessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK); } } }