Asp net gridview rowupdating datakeynames
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.The Grid View Update Event Args class has three important collections – Old Values, New Values and Keys. NET 2.0 Grid View control allows us to quickly edit and delete records. Drag and drop an SQL Data Source control on the web form.However, most of the real world cases call for validating the data being edited or deleted. Open its smart tag and choose “Configure Data Source” option to start Configure Data Source wizard.This tells Grid View that the event handler should be cancelled.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.The Ole Values collection contains list of old column values, the New Values collection contains the list of new values entered by the 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.
Enter the database details as per your setup and click on OK.Now from the smart tag of the Grid View choose “Edit Template” and then select “Edit Item Template” of Company Name column.This will display the template designer for the column as shown in Figure 6.You can not attach validation controls directly to these Text Boxes.We need to convert these Bound Fields to Template Fields.You can attach validation controls to the Template Fields to perform client side or server side validation.If you need more control you can also handle Row Updating or Row Deleting events of the Grid View.Similarly if you set country to “Bharat” it gets replaced as “India”.In this article we learnt various ways of validating data in a Grid View control.Click on the Edit button of the Grid View so that it goes into the edit mode.Make Company Name blank and click on Update button. This way you can attach client side validation controls to the Grid View columns.