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
    • Column header text
  • 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.

posted on Friday, March 7, 2008 1:28 PM
Filed Under [ .Net ASP.Net ]

Comments

Gravatar
# re: Custom GridView
posted by Ganesh
on 6/5/2008 12:04 PM
Hi,
I am in the similar position. i need to develop a gridview allowing user to define what columns should be displayed in runtime. I see in your blog you have already designed a custom gridview. Would you mind helping me with some example code for it? I understand you can not share the code, but i would appreciate if you could email me small snippets of code or any links regarding this.
Thanks a lot,
Ganesh
Gravatar
# re: Custom GridView
posted by Sujith
on 3/29/2010 5:02 AM
Hi,
Me too in the similar position. i need to develop a gridview allowing user to define what columns should be displayed in runtime. Can you help me please

Post A Comment
Title:
Name:
Email:
Comment:
Verification: