Gridview rowupdating in asp net c

posted by | Leave a comment

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.

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.

Make Company Name blank and click on Update button.

Next, drag and drop a Required Field Validation control below the Text Box.

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.

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.

This will convert them from Bound Field to Template Field.

Leave a Reply

lovedatingmarriage com