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

 //验证
        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[0];
            for (int i = 0; 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 > 0) e.RowError = "请按照错误提示操作。";
        }

//公共验证方法

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

 
原文地址:https://www.cnblogs.com/dfxyw/p/5097908.html