The last step is to add validation to editing the record.
For this example I'll show you how to validate that the last name is filled in
and that the email address is in valid form. Stop the project from running to
return to design mode in Visual Studio 2010.
1.
Click the smart tag next to the GridView control again. You're still in
Edit Template mode and you need to exit this mode. To exit this mode simply
click on the End Template Editing link on the pop-up menu.
2.
You should see the GridView control again with the bound fields. Click
the smart tag and click Edit Columns… from the pop-up menu.
3.
Click the LastName field in the Selected Fields list and then click the
Convert this field into a Template Field link.
4.
Do the same for the EmailAddress field. Now click the OK button.
5.
Click the smart tag next to the GridView control again and select Edit
Templates from the pop-up menu.
6.
Select the LastName EditItemTemplate from the list.
7.
Drag a RequiredFieldValidator control next to the textbox.
8.
Set the ControlToValidate property of the RequiredFieldValidator to
Textbox1.
9.
Set the ForeColor property to Red.
10. Set
the ErrorMessage property to Please enter a last name.
11. Click
the smart tag next to the GridView control again. Select the EmailAddress
EditItemTemplate value from the list.
12. Drag
a RegularExpressionValidator next to the textbox.
13. Set
the ControlToValidate property to Textbox2.
14. Set
the ForeColor property to Red.
15. Set
the ErrorMessage property to Please enter a valid email address.
16. Click
in the ValidationExpression property to display a the button with the ellipse.
Click this button. This displays the list of standard expressions. Select
Internet e-mail address and click the OK button.
Now run the project again. Click the edit link and blank
out a name. If you click the update button the validation message should
appear. If you take off the ".com" from the email address you should
also see the email error message when you click Update.