Gridview rowupdating commandargument
When it's all said and done neither of these approaches is particularly complex.
However, if you've never gone down the path of using a Row Command event the discoverability of the above code is practically nil. Last month I was lamenting (to myself) that why are grids still so much work, when so much effort goes into improving other areas of a developer's life? Rick, Maybe I'm missing something, but I've got code that looks like this:protected void Handle Command(object sender, Grid View Command Event Args e)I agree that it would be much easier if the event args included the PK for the row directly, but that seems simpler than what you posted.
For clarity I've explicitly broken out each of the objects here: As you can see getting the PK is now easy - it's simply available as the Command Argument and so it's easy to get context to the underlying data.
However, if you need to get at the actual live data item the work requires first to get the control that fired the event (Link Button), walking up to its naming container (Grid View Row) and then getting the Data Item Index.
From there I can then retrieve the Data Row based on the index.
Again it seems odd given that we are firing a ROW level Row Command event that there's not an easier way to get row level context even when we are using a Command argument.
Template Columns and Commands If something more dynamic is required you need to use template fields.
Personally I prefer using Template fields most of the time anyway because usually it gives you much more control.
Donnie Donnie I think Row Index is not going to work in paged scenarios.Using Template fields with Command Argument and Command Name also fires the fires the same Row Command event on the Data Grid.But the handling of the Grid View Command Argument is quite different.I don't know about you, but I cringe every time I need to create a Grid View based layout that needs to create a few custom link handlers off that grid.The typical scenario might be a list where you can toggle certain options or where you can fire an operation that otherwise updates the data that's underlying the grid.