Skip to content

Table Web Part Connections, IWebPartTable, and PropertyDescriptors

Web part connections are a powerful part of the SharePoint platform. They’re particularly powerful if you think of them as a way to snap together your user interface. I’ve build a tab view control. It looks like you might find in an address book or a dictionary with tabs that show what data is to be displayed on each tab and then a set of columns which show a subset of the records. It’s pretty cool because it allows you to quickly visualize data sets in the hundreds or thousands of rows. I created it to manage sub-sites under a particular part of a navigation hierarchy, but we also want to use it for navigating contacts. There are a few issues with this. I wanted to highlight some of this.

First, the Table connection – which is what I’m using, specifies a IWebPartTable interface. That interface includes a Schema property which is a collection of property descriptors. You can use property descriptors to fetch values out of an object without having to know what kind of an object it is. It’s VERY cool. That’s all fine and good but the ListViewWebPart doesn’t emit a schema. This frankly is VERY easy with the DataView that the web part pushes over. Here’s my generic method for generating the schema that SharePoint should have provided me:

public static PropertyDescriptorCollection GenerateTableSchemaFromData(ICollection data)
if (data.Count > 0)
IEnumerator enumerator = data.GetEnumerator();
object obj = enumerator.Current;
ICustomTypeDescriptor ictd = obj as ICustomTypeDescriptor;
if (ictd != null) return (ictd.GetProperties());
return (TypeDescriptor.GetProperties(obj.GetType()));
else { return null; }

Help Your SharePoint User

This does two things. First, if the collection’s items support the ICustomTypeDescriptor we used that to get the properties, otherwise we get the default PropertyDescriptorCollection for the type.) Again, PropertyDescriptors can get a value from an object – in fact the method is prototyped as GetValue(object obj). Basically, the above code should work for pretty much any kind of data that you get in via the web part connection.

So what happens when the ListViewWebPart sends data is it sends a DataView which is a collection of DataRowView objects. The DataRowView supports ICustomTypeDescriptor which allows us to get back property descriptors for the rows.

The next problem, which I’ve not yet solved for my project is getting the ListViewWebPart to emit the URL as a text field. Thus far I’ve not quite figured out how to trick it into doing that.

No comment yet, add your voice below!

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this: