After specifying the query, we add the appropriate sorting. When you bind a Grid View through a Data Source ID, the Grid View will update this value since it is internally tracking the sort expression, so it knows when to switch between ascending and descending.
We can implement it in this way without a performance impact because the data is not actually retrieved from the database until required, so we can build up a chain of queries up to that point and only the end result will be pulled from the database. When manually databinding the Grid View, this will always show ascending, so we need to handle this manually with the following logic: After that we save the new Sort Expression.
Aspxgridview rowupdating newvalues empty
The important point is not which of these two events call Bind Data, but one of them must or the Grid View will not be updated. When bound using a Data Source ID, the Grid View internally tracks the current Sort Expression and Sort Direction, and those are available through properties with the same names.
When you manually bind the Grid View, this tracking does not occur, so we must implement some mechanism for tracking those values.
Since it’s a Bound Field, the Text Box is going to be Control.
Once we have a reference to the Text Box, we set the new first name.
We also want it to be something persistent, so that, for example, if you sort, then page, the sort is maintained.
The way we’ll accomplish this is to create two properties that store those values in View State.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.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.When the Bound Field is in Edit mode, things are a little different.