Although the Grid View Command Event Args have a Data Item member that member is unfortunately not set with the Data Row as you would maybe expect.So rather than getting the bound item directly, I have to retrieve the grid Row's Data Item index, then use that index and retrieve the value from the original data source.Anyway, the problem isn't that it can't be done 'manually' - but rather that there are a myriad of ways that you can hook up custom link/command processing and they are all similar but yet quite different.
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.
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.
There is a Data Text Field that can be used to display a dynamic value (ie.
Approved which would yield True or False only though) and a Data Format String that can in some cases make this work but for a more dynamic scenario as above that still doesn't do the trick.I tend to use business objects in my applications so using the standard data controls doesn't work very well, nor would it really buy much in terms of abstraction.In my code I tend to write the databinding logic as part of the page logic which usually is just a couple of lines of code.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.At that point I have the data I need to be on my way and do my business logic (which in this case is very simple).