The Grid View 'Grid View1' fired event Row Deleting which wasn't handled. When I say manually databinding I mean not using a data source control specified as a Data Source ID, but rather setting the Grid View’s Data Source equal to the appropriate data object and calling Data Bind. NET 2.0 are familiar with how to deal with this, but since ASP.NET 2.0 most of the examples and tutorials deal with setting the Data Source ID, which buys you a lot of automation that you may not even appreciate unless you’ve done this the old fashioned way.
The Grid View Row is the naming container for the Text Box in this case, so we need to call Find Control on the appropriate row, but we do not need to call it on the specific cell.
Once we have a reference to the Text Box, we set the new last name and save the changes (through the Submit Changes method).
Finally we need to populate the Sort Expression and Sort Direction when they change, and we’ll handle that in the Sorting event. Also like paging, so show that it does get called, databinding is handled in the Sorted Event ( First, we obtain the User ID of the affected row from the Grid View Data Keys collection, which we use to pull the appropriate record from the database.
At that point we need to get the new values so we can update the record, which is done slightly differently for the Bound Field and the Template Field.
We’ll revisit this method when we implement the sorting functionality.
We also need force databinding to occur when then page is loaded, which we’ll handle in Page_Load.
For this example, the Item Template would be transformed into a Literal control, and the Edit Item Template would be transformed into a Literal control, a Text Box, and a Literal control (the literal controls would include the spacing between the Edit Item Template tags and the Text Box tags).
In both cases, the controls are added to the controls collection for the cell.
Once we have a reference to the Text Box, we set the new first name.
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.
When a Bound Field is displaying data (not in edit mode), the appropriate text is added to the Text property of the appropriate cell.