Gridview1 rowupdating old values
Set the Control To Validate and Error message properties to the appropriate values. Up till now we used the validation controls to validate Grid View input on client and server side.Double click on the Custom Validator control to go into the Server Validate event handler and write the following code in it. However, at times you many need more control and flexibility than that is provided by validation controls.By default when the Grid View controls goes in edit mode, it displays Text Boxes for entering values.You can not attach validation controls directly to these Text Boxes.There can be several approaches taken for validating data. For our example we are going to use Customers table of Northwind database. Open its smart tag and choose "Configure Data Source" option to start Configure Data Source wizard.On the first step of the wizard click on "New Connection" button to open a dialog as shown in Figure 1.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.
The New Values collection is read/write collection and in the second if condition we set the Country to India. You will find that the data is not accepted by the Grid View.
This will convert them from Bound Field to Template Field.
Now from the smart tag of the Grid View choose "Edit Template" and then select "Edit Item Template" of Company Name column.
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.