Click on the "Advanced" button and check the "Generate INSERT, UPDATE and DELETE statements" checkbox (Figure 3). Now that you have configured the SQL Data Source control let's bind it with a Grid View control. Open its smart tag and configure it as shown in Figure 4.
Here, we set the Data Source of the Grid View to Sql Data Source1. We also enable paging, sorting and editing features of the Grid View.
By default when the Grid View controls goes in edit mode, it displays Text Boxes for entering values.
Inside the event handler we added two validation conditions: We used the New Values collection to check the entered country.
If the country is null then we set Cancel property of Grid View Update Event Args class to true.
In our example we will illustrate the use of Updating event for the validation purpose.
Add Grid View1_Row Updating event handler as shown below: The Row Updating event handler receives an event argument of type Grid View Update Event Args.
This will display the template designer for the column as shown in Figure 6.
Next, drag and drop a Required Field Validation control below the Text Box.We will use the Custom Validator control for this purpose.Just like we attached the Required Field Validator control to the Text Box, attach a Custom Validator to the Contact Name column. If you run the web form and try entering wrong value in the Contact Name column then you will see the error message displayed as before and the value will not be accepted by the Grid View control.Enter the database details as per your setup and click on OK.On the next step select Customer ID, Company Name, Contact Name and Country columns (Figure 2).This will convert them from Bound Field to Template Field.