Blazor DataGrid Example - Custom Validation

DataGrid / Editing / Custom Validation

This sample shows how to use data annotation to perform custom validation in the DataGrid.

Loading Syncfusion Blazor Server Demos…

1 of 2 pages (20 items)

The Blazor DataGrid Custom validation is used to validate the fields according to the user's condition using data annotation. System.ComponentModel.DataAnnotations namespace must be imported to use the custom validation. The user should create a new class for the field to be customized which must extend the ValidationAttribute. The IsValid method should be overridden to validate the end-user input.

In this demo, the following changes are made in the Grid

  • The namespace System.ComponentModel.DataAnnotations is imported to use the custom validation.
  • Created a class CustomValidationFreight for the Freight property to be validated which extends ValidationAttribute that validates whether the entered Freight value is in between 1 and 1000.
  • Created a class CustomValidationEmployeeID for the EmployeeID property to be validated which extends ValidationAttribute that validates whether the entered EmployeeID value is greater than 0.
  • IsValid method is overidden and accessed the input entered by the end-user.
  • Validated the input entered by the end-user.
  • An error message is shown if the validation is wrong.
  • Created a class CustomValidationFreight for the Freight property to be validated which extends ValidationAttribute that validates whether the entered Freight value is in between 1 and 1000.
  • Created a class CustomValidationEmployeeID for the EmployeeID property to be validated which extends ValidationAttribute that validates whether the entered EmployeeID value is greater than 0.

Try adding a new record in this grid with empty values to see the validations done in the columns.

More information about the Row hover can be found in this documentation section.

Transform your Blazor web apps today with Syncfusion® Blazor components
100+ high-performance and responsive UI components
Dedicated support
Hassle-free licensing
TRY IT FOR FREE