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

How to make GridView respect validation attributes in buddy class

1 Answer 41 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Calvin
Top achievements
Rank 2
Calvin asked on 15 Mar 2012, 05:30 PM
How does one get the GridView to detect property validation attribute violations when they are specified in a buddy class?  For example, the property attributes in the buddy class below are not respected by the GridView.  I.e., the grid doesn't indicate a validation error for and it permits entry of a part number that doesn't match the regex. By contrast, the GridView does respect the IValidatableObject.Validate method.  I've tried making the PartMetadata class public; but it still didn't validate.

Any ideas?  thanks!

[MetadataType(typeof(Part.PartMetadata))]
public partial class Part : IValidatableObject {
 
    private sealed class PartMetadata {
        [RegularExpression(@"[0-9A-F]{4,20}")] // Not respected by the RadGridView 
        public string PartNumber { get; set; }
    }
 
    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
        if (PartNumber == DrawingNumber) { 
            yield return new ValidationResult("part number = drawing number", new string[] { "PartNumber", "DrawingNumber" });
        }
    }
}


1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 20 Mar 2012, 03:15 PM
Hello,

RadGridView validates business objects and its properties via System.ComponentModel.DataAnnotations.Validator class which does not support MetadataType attributes natively. For more information you can take a look at this post.
Indeed RadGridView respects IValidatableObject - for the time being only after row edit is committed, but very soon RadGridView will support such validation in view mode too.

Greetings,
Nedyalko Nikolov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Calvin
Top achievements
Rank 2
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or