Rowupdating does

The Grid View does know the events that should be used to implement them, so the exceptions shown above are thrown when you try to perform one of these operations, but you have implemented the appropriate event handler.

The example shown here is for a Grid View, but the same types of event handlers must be implemented in roughly the same way for other data controls including the Form View, Details View, and List View. This is the final Grid View markup, so you can see the event handlers we’re going to implement.

We’re sorting on the appropriate field based on the Sort Expression, and setting the direction based on Sort Direction by calling either the Order By or Order By Descending methods. As with paging, we also reset the Edit Index and Selected Index when sorting.

rowupdating does-26rowupdating does-53

Since it’s a Bound Field, the Text Box is going to be Control[0].

Once we have a reference to the Text Box, we set the new first name.

If you have handled the Row Updating event, changes will commit immediately to your data source as you lose focus on the edited row.

For a row to obtain or lose focus, you must have the Activation behavior enabled.

We’ll start with binding data to the Grid View, then build up functionality from there.

First, we’ll implement a method to databind the Grid View, which will be called whenever databinding needs to be performed.

We also need force databinding to occur when then page is loaded, which we’ll handle in Page_Load.

The required actions for paging to work are setting the new page index, setting the Data Source, and calling Data Bind (the last two through the Bind Data method).

For the Template Field, we do know the ID of the control since we specified it in the markup, so we obtain a reference to it by calling Find Control on the appropriate row of the Grid View.

Tags: , ,