ASP.NET 4.0 and the Entity Framework 4 - Part 5 - Using the GridView and the EntityDataSource
page 6 of 7
by Vince Varallo
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 34844/ 100

Step 5: Add Validation

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.


View Entire Article

User Comments

Title: vb nvvbnvb   
Name: vbnvbn
Date: 2012-06-06 10:09:02 PM
Comment:
vbn
Title: Cant see images   
Name: jrk
Date: 2012-05-25 9:27:32 PM
Comment:
The images in this article show as big red X
Title: great done   
Name: vishwajeet singh
Date: 2010-09-30 6:44:04 AM
Comment:
its realy great thing what happend through .net 4.0

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-18 6:33:47 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search