来自http://msdn.microsoft.com/en-us/library/f5db6z8k(v=vs.100).aspx
我创建了一个 customeValidators.cs 页面,用于检查输入的数据是否存在于 Db 中。这行得通。但是,当我尝试从必要的页面中调用它时
protected void runUniqueReference(object source, ServerValidateEventArgs args)
{
args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text));
}
我收到错误消息CustomValidators.UniqueReference
,无法将“数据注释”转换为“布尔”任何想法?编辑;
public static ValidationResult UniqueReference(string Reference)
{
ContextDB db = new ContextDB();
var lisStoredInDB =
(from Bill in db.Bill_Of_Quantities
where Bill.Reference == Reference
select Bill.Reference).ToList();
if (lisStoredInDB.Count != 0)
{
return new ValidationResult(string.Format("This reference is already stored in the database, Please enter another"));
}
return ValidationResult.Success;
}