When I started trying to implement last week's database row highlighting sample
in ASP.NET, I naturally looked for a simple and elegant solution. When I was unable to
come up with one easily on my own, I went to the web. Surely someone had done this before.
The answer was bound to be out there just waiting for me to find it. Well I found plenty
of answers, but none of them were very simple, let alone elegant.
The best of what I found came from the place I usually end up finding the best stuff...
Both Creating a Row-Selectable DataGrid Control
An Easier Way to Highlight the Rows of a DataGrid on MouseOver
address the issue at hand and actually do a pretty good job. The problem is
that the first is relatively complicated (it creates a new custom control which
inherits from the DataGrid to get the job done) and the second has some
compatibility issues (which stem from the author's desire to use CSS even
While the solutions presented in those articles are probably technically
"better" then my approach (the reusability and added functionality
of the custom control in particular are big benefits),
I wanted something simple (I'd long since given up on any level of elegance).
So here it is... the secret to getting simple database row highlighting in ASP.NET --
the DataGrid generates, I just used the Repeater instead and built my own table.
It may not be the coolest or most exciting approach (and we already know it's not the most
elegant), but it's pretty darn simple. Just take a look at the code...