Gridview rowupdating keys

Posted by / 21-Jun-2017 08:19

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.

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.

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.

Make Company Name blank and click on Update button.

You should see an error message as shown in Figure 7.

Click on the Edit button of the Grid View so that it goes into the edit mode.Here, our validation criteria is that the entered name must not contain title of courtesy (Mr./Mrs./Ms.). That is when you can handle certain events of Grid View control.We check the value entered in the Text Box using args. Especially the following events are important for validation point of view. 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.

gridview rowupdating keys-24gridview rowupdating keys-65gridview rowupdating keys-26

Inside the event handler we added two validation conditions: We used the New Values collection to check the entered country.