Gridview rowupdating causesvalidation

Posted by / 24-Jan-2017 19:12

Gridview rowupdating causesvalidation

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.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.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.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.

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.

It certainly would be much nicer if the event arguments passed back on these row commands provided a little more information and more consistently. Is there a subtlety which makes this not always work?

Donnie Donnie I think Row Index is not going to work in paged scenarios.

Also notice that if you have both Button Fields/Command Fields and template items that have command arguments, the Command Argument will contain different things.

In the case of a Command Field the Command Argument is the Row Index.

gridview rowupdating causesvalidation-90gridview rowupdating causesvalidation-8gridview rowupdating causesvalidation-70

Template Columns and Commands If something more dynamic is required you need to use template fields.

One thought on “gridview rowupdating causesvalidation”

  1. Dance clubs and dive bars may have worked in the '90s, but now, even if you’re out, your phone is a much easier way to find someone to "watch Netflix and chill" with (especially someone you won’t regret tomorrow).