Tuesday, September 15, 2009

Exposing SharePoint List Data using Data View Web Part

Recently I had the need to create a new view when a user clicked on a list item. This view was formatted like a HTML page, and looked nothing like the default DispForm.aspx that SharePoint shows you by default. Well, I ended up implementing a nifty solution that my colleague at work had used before.

Instead of replacing or customizing DispForm.aspx for the list (which you need to be really careful about), I actually created a new WebPart page in a document library on that site. I cracked open SharePoint designer and threw a Data View/Form Web Part (or the Swiss Army knife as it is sometimes called) and added a URL Querystring parameter to provide me with the ID of the item I was showing. Then I customized the design of the page inside the XSL to show me the view that I wanted.

The last part was to wire up the click event on the list to this new page. I browsed to DispForm.aspx and opened it up in edit mode. Some of you might wonder how is it possible to edit an administrative page? The answer lies in the querystring parameters you provide it in the URL. If you append a querystring ?PageView=Shared&ToolPaneView=2 to the page, then it will open it up in Edit view. From here on, I just hid the list view Web Part and added a content editor Web Part that contained some javascript to redirect to the page in my document library that had the Data View Web Part with the formatting I needed.

No comments: