Asp net datagrid rowupdating
NET 2.0 Grid View control allows us to quickly edit and delete records.However, most of the real world cases call for validating the data being edited or deleted. Drag and drop an SQL Data Source control on the web form.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.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.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.
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.
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).