This is a migrated thread and some comments may be shown as answers.

Issue with the GridView Cell Validation.

0 Answers 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
SivaPrasad Bevara
Top achievements
Rank 1
SivaPrasad Bevara asked on 11 Oct 2012, 12:32 PM

Hi,

I am using Silverlight 5, Doamin service and Telerik Controls(Version 2012.1.215.1050).

I need to validate the grid view cells against the database, in the Edit mode.I am using the CustomValidation function to do this.

Step 1:
Initially when the grid is loaded it edits the errored cell.
When I commit that row without changing anything, then the row background is set to red.
But it is not editing the cell and not showing the error message in the cell.

Step 2
When I edit any other cell in the row and commit the row agian then it is automatically editing the errored cell and displaying the error in a tool tip.

Step 3:
Why it is not automatically editing and showing the error message when grid row is committed initially (when nothing is changed and committed).

But in this case the row background is changed.
Is there any GridView property that specifies the grid has a error?
I tried with RowStyleSelector property, but it is null.

Following is the code which I am using to set the error.

In the DTO class

[CustomValidation(typeof(CustomValidationRules), "CheckAccountExists")]
public string Emp_ID { get; set; }

Following is the Custom Validation function in the Shared file.

public static ValidationResult CheckAccountExists(string Emp_ID, ValidationContext vContext)
        {
  
#if SILVERLIGHT
           ValidationResult errorResult = new ValidationResult("Account Id not valid. Add before using.",
                    new string[] { "Emp_ID" });
                EmpDTO txn = (EmpDTO)vContext.ObjectInstance;
             
                PostingErrorsDomainContext _Context = new PostingErrorsDomainContext();
                InvokeOperation<string> availability = _Context.CheckAccountExists(Emp_ID);
  
                availability.Completed += (s, e) =>
                {
                    if (!availability.HasError && availability.Value != "")
                    {
                                                  Entity entity = (Entity)vContext.ObjectInstance;
                            if (!entity.ValidationErrors.Any(v => v.ToString() == errorResult.ToString()))
                            {
                                entity.ValidationErrors.Remove(errorResult);
                            }
                            entity.ValidationErrors.Add(new ValidationResult("Account Id not valid. Add before using",
                            new string[] { "Emp_ID" })); 
                         
                    }
  
                };
#endif
            return ValidationResult.Success;
        }

Please help.

Regards,
SivaPrasad.B

No answers yet. Maybe you can help?

Tags
GridView
Asked by
SivaPrasad Bevara
Top achievements
Rank 1
Share this question
or