Way back in March I posted about a custom GridView I was working on.  Then in June, I said that I would be posting some guidelines "in the coming weeks".  Needless to say, I've been busy with other things. 

I am hoping to provide some basic guidelines on how to customize a ASP.Net GridView.  I am no expert.  The experts build components for retail use.  Also, I've taken a server-side approach to the problem which is perhaps a little outdated with AJAX technology available.  In my case, I use an UpdatePanel to handle partial postbacks.

I will be using the specific example of selecting rows by a simple click, rather than adding check boxes to indicate selection.  Selected rows are identified by a background color (technically by a css class).  Also, selecting multiple rows will be supported and selection will be very much like the standard Microsoft uses within all of it's applications.  The Shift key will be used to select a range, while the Ctrl key will be used to select (or deselect) one item at a time.

As I've stated, this is a server-side approach.  Initially I ended up with a single control class that was cluttered with all of my customizations.  I refactored to something similar to a model-view-controller or an observer where a class responsible for a specific customization would observe events on the GridView.  This allowed me to do a couple of things.  First, it made testing the custom behavior a lot easier as I was able to mock my GridView and isolate the new behavior.  Second, it eliminated a lot of clutter.

A good approach regardless of your design is to use TDD.  I didn't do this initially and I should have.  I talk about that a little bit here.  Think about your requirements and how you would test them.  Then get started by writing a test and implementing some behavior.

What's Next?
Next I plan to take a look at the interface between my GridView and the selection controller.

posted on Thursday, November 6, 2008 12:47 AM
Filed Under [ .Net Design Design Patterns ASP.Net C# ]


No comments posted yet.

Post A Comment