D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

Highlighting Data Grid Row (con't)

Thursday, December 15, 2005 11:28 AM

I like Greg's solution, but I don't think that one is necessarily better than the other. A given situation, I would think, would determine which one would be better to implement.

First off, I totally agree with Greg in that color values should be within a style sheet. The colors I included were more for example, but hard coding them in the code behind isn't the best approach. Greg mentions in one of his feedback posts that doing it that way would require a recompile, which is true. It should be noted that with 2005, ASP.NET apps are recompiled on the fly, so you *could* just upload a new .vb/.cs file...but css is still much better.

Greg mentions that his solution was actually used to upgrade an unholy amount of datagrids within an application that all needed the same look for highlighting rows. His solution is perfect in that scenario: drop two files into the application, and done.

But what if that application was at the beginning of development, or what if there was extra logic that was necessary? For instance, what if, based on a value in that row, the highlighted color on mouse over needed to be different; maybe red instead of green. In the code behind, you could specify a seperate class to assign to the OnMouseOver event. You can't do that with the pure javascript option because you'd need to write specific code for each scenario. Or what if you wanted different script to execute...maybe you want an alert dialog to show, or an image on screen to change, etc. That's all custom, and that all can be handled from within the code behind much better.

Is there really a “substantial“ amount of HTML that gets saved? Not really. In the most simplest case, “OnMouseOver = ... OnMouseOut = ...“ is about the only thing that would be added for each line of the grid. What if you have alot of rows? Use paging (that's a different discussion I'm sure though). Again though, the situation will also dictate whether the amount of HTML going over the wire makes sense or not. I worked on a project recently that utilized datasets to transport data over dial up connections down to a web service. It made absolutely no sense to send all the extra dataset-stuff and we changed it to send only pure XML to speed up the transportation.

The point is this: different solutions for different scenarios. One solution isn't better than another, unless its debating the best solution for a given scenario. It wouldn't make sense to go back and alter code for all of those grids in Greg's case. Fair enough. But in the scenarios where I've used that bit of code before, it made perfect sense.

I do love the idea that his code can be applied to any html...very cool solution.





No comments posted yet.

Post a comment