CheckBox GridView Column with a web service call
A short while back I made a quick post on how to create a GridView with a column of checkboxes, then I created a JQuery function to check all of those at once. The idea being that I wanted reduce post-backs on the page.
Well, I had to revisit that idea today. My problem wasn’t with the Check All button that I made, that works fine, the problem was with the the check boxes in the grid view column themselves. I was using the built in Asp.Net AJAX UpdatePanel to handle talking to the code behind EVERY time a check box what checked.
Worked fine on small grids with good connections. But large grids with bad connections…not so much. The problem was that the entire grid was being reloaded with every check box click. Not good. If you want to see more reasons on why to beware UpdatePanel see Encosia’s “Why ASP.Net AJAX UpdatePanels are Dangerous“.
Next comes up hooking up the CheckBox. Now, if all I had to do was set the onclick property to call the function, it would be easy. The code would look like this:
But I need more data than that. I also need to username. Plus, this is in a GridView. So I actually have to catch the OnRowDataBound event, and set the attribute programmatically.
Much, much, much better.