Andrey Markeev on SharePoint

Blog on SharePoint: Series

October 29, 2012

I always wanted to have automatic Series tracking on my blog. So i.e. when you're writing some long thing breaking it into several posts, the links to the posts are automatically updated every time a new post gets published. Manually maintaining those links is boring and also it sometimes messes up your RSS, because posts get updated and thus they go up in the feed.

Now I have it all automatically, RSS isn't affected, all is great and works. You can see the thing at the bottom of this page. And it was implemented, once again, as a simple DataFormWebPart! :)

Actually, the implementation part was a bit tricky, that's why I'm writing this post.

So basically how can you track series? Since my blog is a document library, I can just add some "Series" column to the library (most likely it will be a lookup field to some "Series" list), and then in my data view I should filter by this "Series" column, right?

In other words, I need to create a DataFormWebPart, which displays posts belonging to current series. Easy, isn't it? Uh, I thought so :)

So I opened my SharePoint Designer, and created a simple DFWP pointing to the articles library.

By the way, are you aware of this handy View Style feature? You see, by default, your Data View is rendered as a table. But "Posts of this series" obviously should look like a list, not a table! And wow, it turns out you can just switch the view to be an ordered list, instead of processing all those XSLT changes manually:

Very convenient indeed. Of course, some changes are still necessary, but they are minor now:

  1. Wrap title in link, so that it points to the corresponding article page

  2. Add "Posts of this series" header before the list.

  3. Clear empty template in order to avoid "There are no items in this view" message.

Just for clarity: I'm a developer to bones. I'm perfectly aware of XSLT and it's not a problem for me to write as much XSLT as it is necessary. And some time ago I was writing tons of XSLT, yet now I prefer to give SPD the pass to do as it wants, even although some of its changes are not perfect.

That's neither because I'm in love with SPD nor because I'm lazy, however both true :) It's just because it's much faster.

I can create almost any possible data view with SPD in no more than 5 minutes. Writing similar XSLT from scratch, even not touching all these DataSource settings, would take at the very least twice that! And if you don't know XSLT well enough, it could actually take hours for you.

So let's get back to my Series DFWP. This is what I've got after applying ordered list style:

Now to wrap post titles into hyperlinks, I selected a title, then clicked "Hyperlink" ribbon button (Insert tab), and picked URL Path field from the formula editor (fx button).

Ok, now I can switch to Code view and perform some XSLT coding at last :)

First task (avoid "No items to show in this view" message) was very simple, I found "dvt_empty" template and just removed all the contents inside this tag.

Then, in "dvt_1" template, right before "<ol>" tag, I inserted "<h4>Posts of this series</h4>".

Ok, now it looks fine, and it's time to filter the dataset (back to Design view, select DFWP, click "Filter" button on Ribbon). So basically the condition should be "[value of Series column] equals to [value of Series column of the current page]".

Here, in the Filter Criteria dialog, SPD allows you to pass either a hardcoded value or a parameter. Since in my case the value obviously cannot be hardcoded, I created a new parameter. Parameters can be of different types, and the types are actually not limited to those which are presented in SPD.

The most comprehensive description of those parameters' types (actually in markup, they're presented by ParameterBinding tags) can be found in Stefan Stanev's blog post.

Unfortunately, even in the mentioned above blog post, although it is in fact covers more details than you can find on MSDN, there is no parameter type (ParameterBinding Location value), which can be used directly for fetching a property from the current page.

But as you probably know, OOTB way to render current list item properties to the page is to use ListItemProperty control. And among parameter types you can notice "Control" type, which can bind parameter to property value of some server-side control on the page.

Unfortunately, it turns out that the ListItemProperty control doesn't expose any property which contains the desired value. It just renders the value to the page, but doesn't store it in a public property. No luck.

I started to google on this topic, trying to find a solution, and stumbled upon a very good post by Jussi Palo: SharePoint: Filter Data Form Web Part using Metadata value of current Publishing Page. This blog pointed me to the right direction: you can use one of BaseFieldControl-derived controls for binding to the DFWP, leveraging ItemFieldValue property!

Note: it seems that ItemFieldValue property yields the field value only if the control which you're using correctly corresponds the field type. For example, value of a field of type MultiChoice can only be fetched through the CheckBoxChoiceField control.

Woo-hoo! Now, having this knowledge in mind, I created control "CurrentArticleSeries":

<SharePoint:LookupField ID="CurrentArticleSeries" FieldName="Series" Visible="false" runat="server"/>

Then, I pointed my ArticleSeries parameter to this control's ItemFieldValue property:

And yes, that's that, I've got DataFormWebPart for automatic series tracking!

Wrap up

  1. DataFormWebPart is a very powerful OOTB SharePoint webpart, it can be used in many real scenarios for pulling data from lists and various other data sources.
  2. It takes only a couple of minutes to create and configure such webpart using SharePoint Designer.
  3. DataFormWebPart can have dynamic parameters. Parameters can be fetched from query string, control property, server variable, etc., and used when accessing the data source and also inside XSLT.

Please, feel free to ask any additional questions in the comments!

Like it?

Posts of this series

  1. Public blog on SharePoint
  2. Blog on SharePoint: Series (this post)
  3. Blog on SharePoint: RSS feed

About me

I'm SharePoint MVP, published author, frequent speaker, opensource projects creator and online expert.

I'm one of the top 10 experts on SharePoint StackExchange:

profile for omlin at SharePoint, Q&A for SharePoint enthusiasts

You can learn more about me on LinkedIn and Facebook.

Want to follow?

Subscribe to RSS!


Blog archive