Devexpress 中如何写ASPxGridView新增修改时的数据验证

时间:2021-04-02 05:54:43
 //验证
protected void grid_Deptlist_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
if (e.NewValues["DEPNAME"] == null)
{
AddError(e.Errors, this.grid_Deptlist.Columns["DEPNAME"], "部门名称必填!");
} DataTable dt = new DataTable();
dt = customerservicebll.DeptList(PEOID).Tables[];
for (int i = ; i < dt.Rows.Count; i++)
{ if (dt.Rows[i]["DEPNAME"].ToString() == e.NewValues["DEPNAME"].ToString())
{
AddError(e.Errors, this.grid_Deptlist.Columns["DEPNAME"], "对不起,您输入的部门名称已存在!");
}
} if (e.Errors.Count > ) e.RowError = "请按照错误提示操作。";
} //公共验证方法

  void AddError(Dictionary<GridViewColumn, string> errors, GridViewColumn column, string errorText)
  {
    if (errors.ContainsKey(column)) return;
    errors[column] = errorText;
  }