CSFrameworkV6旗舰版 - 表格多选操作删除记录
CSFrameworkV6旗舰版 - 表格多选操作删除记录
显示复选框
数据查询页面的表格默认不可修改数据,需求通过代码显示复选框:
C# 全选
gvSummary.AllowGridMultiSelect();
AllowGridMultiSelect 是个扩展方法:
C# 全选
/// <summary>
/// 允许表格多行勾选功能
/// </summary>
/// <param name="view"></param>
public static void AllowGridMultiSelect(this DevExpress.XtraGrid.Views.Grid.GridView view)
{
view.OptionsSelection.MultiSelect = true;
view.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
}
获取勾选的记录主键值
C# 全选
//获取勾选的记录主键值
var keys = gvSummary.GetCheckedKeys<sys_LanguageData>(w => w.isid);
var keyValue = String.Join(",", keys);//转换为,分割的字符串
调用删除方法
C# 全选
bool b = _BLL.Delete(keyValue);
DAL层删除数据
C# 全选
public override bool Delete(string keyValue)
{
var keys = keyValue.Split(',').ToList();
var list = _Database.GetQueryable<sys_LanguageData>().Where(w => keys.Contains(w.isid)).ToList();
if (list.Count > 0)
{
var result = _Database.Remove(list) > 0;
//数据日志
if (result) _Log.Log(DataLogType.delete, "删除语言", nameof(sys_LanguageData), keyValue, _Loginer.Account);
return result;
}
else
{
throw new BizException("主键 <" + keyValue + "> 不存在,删除失败!");
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网