[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]ASP.NET WebForms Controls
   Getting Started
  [Collapse]Grid View
   [Expand]Product Information
    Getting Started
    [Expand]Binding to Data
    [Expand]Data Representation Basics
    [Expand]Focus and Navigation
    [Collapse]Data Editing
      Edit Form
      Adding and Deleting Records
      Row Validation and Error Indication
      Edit Form Validation (Templates)
      Processing Custom Callbacks
      Batch Edit Mode
    [Expand]Data Shaping and Manipulation
    [Expand]Data Formatting
    [Expand]Master-Detail Relationship
     Appearance Customization
    ASPxGridView Designer
   [Expand]Visual Elements
   [Expand]Member Tables
  [Expand]Tree List
  [Expand]Card View
  [Expand]Chart Control
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Site Navigation and Layout
  [Expand]HTML Editor
  [Expand]Vertical Grid
  [Expand]Data Editors
  [Expand]Docking and Popups
  [Expand]File Management
  [Expand]Data and Image Navigation
  [Expand]Multi-Use Site Controls
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]ASP.NET MVC Extensions
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Row Validation and Error Indication

This topic describes how to check the validity of data entered by end-users into a Data Row. ASPxGridView allows you to manually validate an edited row, and display error icons for invalid fields.

Expanded Validating Rows

To implement row validation, you should handle the ASPxGridView.RowValidating event. This event is automatically raised when a row is about to be updated, and allows you to specify whether its data is valid or not. To manually force row validation, call the ASPxGridView.DoRowValidation method.

  • The event's OldValues and NewValues properties allow old and new row values to be obtained, respectively. These properties represent collections. Individual row values can be obtained via index notation or by specifying the field name. The event's IsNewRow property identifies whether or not a new row is being edited by the user.
  • If the value is invalid, use theErrors property to specify the error description text. As a result, an error icon will be displayed next to the invalid value. Pointing to the icon shows a hint with an error description.
  • Use the RowError property to specify the error text displayed within the Error Row. This row is automatically displayed below the edited row if the RowError property is set to a non-empty string.

    Use the ASPxGridBehaviorSettings.EncodeErrorHtml option to specify whether or not ASPxGridView keeps its row errors that are HTML as HTML, or strips out the HTML markers instead.

Expanded Validating Edit Cells

Data columns provide various validation settings available via the EditProperties.ValidationSettings property. This allows you to define the validation logic for individual edit cells.

For example, you can use the ValidationSettings.RequiredField property to force an editor to require input, and specify an error message if input is not received.

Expanded Example

This example demonstrates how to check the validity of data entered by end-users into a row. Validation is implemented within the ASPxGridView.RowValidating event handler. In this sample, validation fails in the cases listed below:

  • field value(s) is empty;
  • Contact Name and/or Company Name fields are set to a single character.

The ASPxGridView.HtmlRowPrepared event is handled to paint the row's contents red if the row is invalid. This event is raised for each data row when the corresponding row within the table has been created. This indicates rows within invalid data.

The ASPxGridView.StartRowEditing event is handled to display errors (if any) within the edited row when an end-user switches to an edit mode.

Expanded See Also

Is this topic helpful?​​​​​​​