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

Validation using Data Annotations

1 Answer 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 27 Feb 2013, 12:49 PM
Hi
I am using data annotations to validate items in a collection presented in a RadGridView.
It successfully validates a property of an item in the collection e.g. a name is required
// ...
{
    public class GroupOfItems
    {
        [Required(ErrorMessage="Name must be provided!")]
        public string GroupName { get; set; }
// ...

I now want to ensure the name is unique within the collection. I have tried adding the [Key] attribute but no error is indicated if I enter another item with the same name. It may be that [Key] is not appropriate in this context.

What can you suggest I do to implement this validation rule?
Thanks
Craig
PS. I'm using C#, WPF, MVVM, Rad Controls for WPF 2012.3.1129.40

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 28 Feb 2013, 08:59 AM
Hello,

There is no built-in "UniqueAttribute" in DataAnnotation assembly, such attribute cannot be general (it depends from user collection). You could write your own just create an attribute class which inherits from DataAnnotation.ValidationAttribute abstract class.

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Craig
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or