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.

rowupdating cell value-62

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.

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.

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).

When the Bound Field is in Edit mode, things are a little different.

In that case a Text Box is created and added to the Controls collection for the appropriate cell (and it's the only item added to the Controls collection, so it's Controls[0]).

If we were using a Template Field instead, the compiler translates the markup in the templates to the appropriate types of controls in the same way as the page markup in parsed.

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).

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.

For the Bound Field, we don’t know the ID of the Text Box since it’s autogenerated by the Bound Field, so we obtain a reference to it by getting the first control in the appropriate cell in the edited row.

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.