Styling webpart data with the Data View Web Part

One of the things that as been driving me crazy is the inability to selectively style webparts. On the home page of my company’s intranet, I have several webparts pulling content in, and they all look the same. I primarily wanted to make the announcements web part look different. I tried every hack I could think of to find some kind of unique hook to attach some styling to. I would change the title style and then watch it change ever title on the page. I have been trying to find uses for the data view web part and so I thought, maybe I can use that to pull in the announcements and then style them…

Long story short, it worked. Using the dvwp I was able to pull in the announcements list, set what fields to display, and then individually style the display of those fields.

First, I created a page layout. You can’t add the dvwp to pages directly unless you create a page based off a page layout and then detach that page from the page layout in SPD before you work on it. On the page layout in Sharepoint Designer, I selected a web part zone, clicked on Data View in the toolbar, and then selected Insert Data View. I then pulled the announcements list onto the dvwp area. I clicked on the arrow to the right of the DVWP and the Common Data View Tasks box displayed.
Common Data View Tasks

First, I edited the columns. I removed all but Title and Body. Then I changed the layout to Repeating Form Style. I then set the paging to display items in sets of 4. Under Sort and Groups, I set it to sort by Created, descending.

Now it was time to style the content. First, I removed the word Body that displayed right over the body content. Then I moved the title xsl code to right above the body code. I created two styles, one to handle the title and one for the body. I wrapped the styles around the fields and then cleaned up the display a bit by removing the extra row, hr and br tags.
Wrapping styles around the fields.

Once that was done, I saved the layout, checked it in and then created a new page based off that layout. The dvwp displayed on the page as a webpart. I exported the webpart and then added it to the Web Part Gallery. I went to the intranet home page, put it in edit mode, and then added the webpart to the page.

One note, I tested this on my dev server first and made sure it worked before I tried it on production 😉

Allowing users to add publishing pages

I have a subsite that I wanted to give over to our Documentation group to maintain. It is a publishing site with a custom page layout. I tested the security with a test user account. I gave the test account full control access to the subsite. When signed in as the test user, I could see the Site Actions button, see pages, security, etc. But when I would try to add a page, I got an Access Denied error. I tried it on a different subsite to just see if there was something wrong with that particular site, and I still got the error. After digging and poking around the web, I found a reference to give the user read access to the Master Page gallery. I gave the test user read access to the master page library and then signed back in and voila, it works!

Sometimes SharePoint just doesn’t make sense, with all the hoops you have to jump in to do seemingly simple things. Like add reusable content lists to a page layout. All i want to do is just add the references to two reusable content lists directly into a page layout so they are there when i make my pages. Apparently, to do this requires custom programming, still waiting on the estimate. In the old days, I’d simply add a library item into a Dreamweaver template and call it a day. Bah.