views:

280

answers:

2

Is there a way to extend the SPGridView control in a webpart such that a user can select the columns that they want to display? Kinda like when creating/modifying a view for a list?

Thanks

+1  A: 

SPGridView is not sealed so certainly it can be extended with this functionality. You would need to build your own data store of what users have chosen (a SharePoint list should suffice), make the UI modifications, etc.

One thing I've found when trying to extend the provided SharePoint controls is that even though most aren't sealed, often they aren't designed to be extended either. In some cases the members are obfuscated as well which in some cases can put an end to extension plans.

Make sure you research this as much as possible with some quick proof of concepts before devoting to this development. You may find it's necessary to write your own control from scratch (or find another standard ASP.NET control that provides this functionality and hook it up to a SharePoint data source).

Alex Angas
More specifically, you would just need to dynamically create the SPGridView's BoundFields and you will be good to go.
Kit Menke
So if I were to add a custom property that has a list of all the Boundfields, and then when they hit update, that should work? What about ordering those fields? How would I even get to the BoundFields from a properties of a Webpart? Is that a wrong approach?
esp
What I did is make a little XML config that was stored in my web part properties that defined the BoundFields. Then, the web part code could load the XML and figure out which BoundField's to make. Order can be changed by changing the order they are specified in the config.
Kit Menke
A: 

I need to do exactly this too, so any help from anyone would be appreciated as I am new to Sharepoint and SPGridviews. I initially want to display 5 columns in the SPGridview as the default, which will be populated from a SQL server db. The user will also have the ability to add more columns to the SPGridview, from a list of other fields held in the datasource that were retrieved from the SQL db.

fraser rush