Gridview rowupdating datakeynames
None of them feels natural to me, so quite frequently - especially if I haven't written that code in a while - I spent way more time than I should rediscovering what approach I should use the hard way.
So I'm taking a few minutes - for my own sake - to write this stuff down so I can look it up next time I have a brain fart Using a Button Field you can specify a Command Name which in turn provides the On Row Command event some context as to what type of operation you are dealing with in Code Behind.
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.
Personally I prefer using Template fields most of the time anyway because usually it gives you much more control.
Using Template fields with Command Argument and Command Name also fires the fires the same Row Command event on the Data Grid.
Let us explore how to insert new records and Update and Delete existing records in Gridview. We will be using the ‘Categories’ table in the ‘Northwind’ database.
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.
In the event handler the code to retrieve the PK in this case becomes considerably simpler, but as we'll see it's a little harder to get a reference to the underlying data source control if that needs to be updated.