2013-01-25 32 views
0

http://msdn.microsoft.com/en-us/library/f5db6z8k(v=vs.100).aspx無法將「數據註解」到「布爾」

我創建了一個頁面customeValidators.cs,如果輸入的數據存在於Db爲檢查。 這有效。然而,當我嘗試從必要pagewith

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; 
    } 
+1

什麼CustomValidators.UniqueReference的返回類型(字符串)? –

+1

什麼是'UniqueReference'及其返回類型?在CustomValidators類中沒有稱爲UniqueReference的方法。 –

+0

請參閱編輯 – John

回答

1

args.IsValidbool類型,CustomValidators.UniqueReference不能返回該類型的值。因此,

args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text)); 

將無法​​正常工作,因爲你不能分配任何的UniqueReference返回值是IsValid

由於UniqueReference返回ValidationResult,大概應該是這樣的:

args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text)).IsValid;