We need to convert these Bound Fields to Template Fields.In order to do so select "Edit Columns..." from the smart tag of the Grid View. Select Company Name and Contact Name fields and click on "Covert this field into a Template Field" link.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.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.
On the first step of the wizard click on "New Connection" button to open a dialog as shown in Figure 1.Set the Control To Validate property of Required Field Validator control to Text Box1 (i.e. Also, set its Error Message property to "Please enter company name".Note that by default all validation controls validate on the client side.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.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.Right click on the Grid View and select "End template editing" Run the web form.Click on the Edit button of the Grid View so that it goes into the edit mode.The Grid View Update Event Args class has three important collections - Old Values, New Values and Keys.The Ole Values collection contains list of old column values, the New Values collection contains the list of new values entered by the user and the Keys collection contains the list of primary key values as defined by Data Key Names.