Likewise, Check Box Fields, which are disabled in the standard, read-only interface, are converted into enabled check boxes in the editing and inserting interfaces.While the default editing and inserting interfaces for the Bound Field and Check Box Field can be helpful, the interface lacks any sort of validation.
The Template Field's Item Template is used to when rendering read-only fields or rows in the Details View or Grid View controls, whereas the Edit Item Template and Insert Item Template indicate the interfaces to use for the editing and inserting modes, respectively.In this tutorial, we'll see how easy it is to add validation controls to the Template Field's Edit Item Template and Insert Item Template to provide a more foolproof user interface.(19 printed pages) Download the code for this sample.Introduction Step 1: Replicating the Example from "Tutorial 17: Examining the Events Associated with Inserting, Updating, and Deleting" Step 2: Converting the Bound Fields into Template Fields Step 3: Adding the Validation Controls to the Grid View's Edit Item Templates Step 4: Summarizing Data-Entry Problems Step 5: Adding the Validation Controls to the Details View's Insert Item Template Step 6: Partitioning the Validation Controls into Validation Groups Conclusion The Grid View and Details View controls in the examples we've explored over the past three tutorials have all been composed of Bound Fields and Check Box Fields (the field types automatically added by Microsoft Visual Studio when binding a Grid View or Details View to a data source control through the smart tag).Additionally, the page included a Details View whose Default Mode property was set to Insert, thereby always rendering in insert mode.
From this Details View, the user could enter the name and price for a new product, click Insert, and have it added to the system (see Figure 1). The previous example allows users to add new products and edit existing ones.If a user makes a data-entry mistake—such as omitting the Product Name field or entering an invalid value for Units In Stock (such as -50) —an exception will be raised from within the depths of the application architecture.While this exception can be gracefully handled as demonstrated in the previous tutorial, ideally the editing or inserting user interface would include validation controls to prevent a user from entering such invalid data in the first place.Our goal for this tutorial is to augment the Details View and Grid View to provide validation controls.In particular, our validation logic will: Before we can look at augmenting the previous example to include validation, we first need to replicate the example from the Data Modification page to the page for this tutorial, Specifically, this tutorial takes the example created in Tutorial 17: Examining the Events Associated with Inserting, Updating, and Deleting and augments the editing and inserting interfaces to include appropriate validation.