A few nights ago I decided to work on a custom GridView. My goal (derived from a customer request) was to build some additional behavior into the GridView without having to write a whole bunch of client-side or code-behind code.
These are the things that I am focusing on:
- Select a row when the user clicks on it (no CheckBox)
- Allow the user to select multiple rows (using Shift and Ctrl keys)
- Bind display settings to site preferences
- Bind display settings to user preferences
- Columns to display
- Column order
- Default sort
I got the first two working quite well. I have tested in IE7 and FireFox. For selecting a row OnClick I simply overrode the CreateRow method of GridView and added the "Select$n" command postback reference to the row.
To select multiple rows, took a bit more work. I added a child HiddenField to identify which keys where pressed when the user clicked on the row. I wrote a JavaScript function to capture the shiftKey and ctrlKey values from the event metaobject. I defined the OnClick for the row to call this function prior to the postback reference. Then, I overrode the RaisePostBackEvent method to change how the "Select" command works. Needless to say, there is a lot more to take care of to make the selections persist between postbacks and to determine when to clear the selections.
Normally, I would be glad to share my code. However, as I am developing this on behalf of my employer, I cannot. I searched for something like this before I tried to reinvent the wheel. I simply took bits and pieces of what I saw other people doing and made work for me.
As an interesting side note. For a former employer I implemented multi-select purely client side. It worked great except that it was difficult (near impossible) to persist the selections after a round trip to the server. I think the next step/test is to AJAX enable my GridView and make selection changes without a full page refresh.