Rowupdating event in aspxgridview
In both cases, the controls are added to the controls collection for the cell.
You can see that in the case of a Template Field, the exact spacing within the control becomes significant, so it’s generally better to get a reference to the control by ID using Find Control than to use the Controls collection.
In addition to that, we’re resetting the Edit Index and Selected Index when the page is changed to avoid cases, for example, where you change pages and are suddenly editing a different item.
Bind Data could be called in Page Index Changing, but to show that it the event is raised, we’ve handled that in Page Index Changed.
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).
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.
In this example, we’ll go through a fully featured Grid View with editing, deleting, selecting, sorting, and paging functionality that is manually bound and identify the limitations and some of the workarounds. Sql Data Source, Object Data Source, Linq Data Source, etc) specified in a Data Source ID, the Grid View can automate many functions because, through the data source control, the Grid View on its own can perform the following operations: When you manually bind data to a Grid View, the Grid View itself cannot perform these operations, so they must be implemented in your code.
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).
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’ll get to how these properties are populated shortly, but first we need to go back to the Bind Data method.
The original method shown above did not implement any sorting, but now that we have a place to store the Sort Expression and Sort Direction we need to change that.