Follow me on Twitter: @eusp

Quote of the Day web part, the Data View way…

Original Publication Date: Thursday, March 5, 2009
Filed Under: Asif Rehmani, Question of the Day, Web Parts, sharepoint designer
SharePoint User Level: Power User

 

Articles in this Series

In my first post, I had mentioned that the mighty Data View web part (DVWP) has many potential applications in the real world. While thinking about what I wanted to show in my first example of the DVWP, I felt inspired by Mark and his team who had created a Quote of the Day web part (QOTD as termed by Mark) using the Content Editor web part (CEWP) and some javascript… a very nifty solution. The quotes in that web part are embedded within so you can change them by directly going to the source editor of CEWP.

The solution that I have presented in this article is a bit different from the other QOTD. It utilizes the DVWP as the presentation component.

Quote of the Day

The quotes are all contained within a SharePoint list where they can be managed easily.


Quote of the Day

To create this solution, you need at least Windows SharePoint Services 3.0 running at the server level and a copy of SharePoint Designer 2007 running at your client machine. The steps that I have posted below to create this solution assume intermediate knowledge of the overall SharePoint system.

The Creation Process

The first thing you will need as the repository of your quotes is the Quotes list.

  1. Create a Custom List on your site and name it Quotes
  2. As pictured in the image above, create two columns in the List: Day (type: Single Line of Text) and Quote (type: Multiple Lines of Text)
  3. Populate the Day column with numbers from 01 to 31 and the Quote column with your quotes
  4. After the creation of the Quotes list, you now need to create the presentation layer with the Data View web part. This web part needs to be configured so that only one quote is displayed at a time and this quote should correspond to the current date of the month.

  5. Start SharePoint Designer and open your SharePoint site
  6. Open up an existing web part page (for example the home page of the site) or create a new web part page to hold your Quote of the Day web part
  7. Click on menu item Data View à Manage Data Sources
  8. In the Data Source Library task pane, click the drop down arrow besides Quotes list and then select Show Data
  9. Select the Quote list item and drag it in the zone

  10. Quote of the Day

  11. You will notice two headings at the top of this web part: Quotes and Quote. Right click on the Quote row, select Delete à Delete Rows
  12. Click on the Chevron (arrow that appears at top right of Data View) to bring up the Common Data View Tasks dialog box
  13. Quote of the Day

  14. Select the Paging option. Change the number 10 to 1 (to display only 1 quote at a time) and click OK
  15. Back at Common Data View Tasks dialog, click on Filter
  16. In the Filter Criteria dialog that shows up, check the box for Add XSLT Filtering and then click on the Edit button
  17. The Advanced Condition dialog should now be visible. Insert the following syntax for the xpath expression: [@Day=substring-before(substring-after(ddwrt:Today(),'/'),'/')]. Click on OK
  18. Note: The xpath expression above says that the filter criteria resolves to the date of the current month. So for example, if the current date is “3/22/2008”, it will return the value “22”

  19. You should now be back at the Filter Criteria dialog, click on OK here as well
  20. Save the page and preview it in the browser. You now should see the Data View web part showing the Quote corresponding to the current date from the Quotes list
  21. Rename this web part (using browser or SharePoint Designer) to Quote of the Day and you’re all done!

Quote of the Day

Using some simple techniques, the Data View web part now serves as the Quote of the Day web part. Not just that, but the content can be easily managed from the Quotes list.

If you’re like me, you probably want to see these steps being done by someone for an even better visual depiction. Not a problem! I have created a screencast which will guide you through these steps. Not just that, but I have gone a step further and also posted the finished solution that you can implement directly on your site without needing SharePoint Designer. All of the information you need is located here: http://www.sharepoint-elearning.com/Pages/QuoteOfTheDay.aspx

Enjoy!

Asif RehmaniAuthor: Asif Rehmani – SharePoint Server MVP, MCT
Website: SharePoint eLearning

Asif has over 10 years of training and consulting experience in the IT industry. He has been training and consulting on primarily SharePoint technologies for over 4 years. He is a SharePoint Server MVP and MCT.

Asif is the co-author of the book Professional SharePoint Designer 2007 by Wrox publications. He has also been a speaker on SharePoint topics at several conferences over the years including Microsoft’s SharePoint Conference, SharePoint Connections, Advisor Live, and Information Workers Conference.

Asif runs a SharePoint eLearning website (http://www.sharepoint-elearning.com) which provides dozens of SharePoint Video Tutorials. He was the co-founder and is currently one of the active leaders of the Chicago SharePoint User Group.

Spread the word...
  • Digg
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • LinkedIn
  • Reddit

Articles in this series


Notify me of comments to this article:


Comments

4 Responses to “Quote of the Day web part, the Data View way…”

  1. How the Data View Web Part Can Enhance the Quality of Your Life | End User SharePoint on March 4th, 2009 1:33 pm

    [...] Quote of the Day web part, the Data View way… [...]

  2. Caleb on March 5th, 2009 12:42 pm

    Thank you very much for sharing this (and including a screencast). I have little experience with xslt, so I was wondering if there was a substring that you could put in that would randomly pull a quote rather than have a quote for a particular day.

  3. Dene on March 8th, 2009 6:49 pm

    Wonderful article. Thanks! Would you possibly answer a question for me? I have configured a DVWP to show our newsy items from several teacher sites – title and body from a custom list. I have it showing 5 things at a time. I need to filter it so it only shows CURRENT news (today and 5 days back). Also need to figure out how to truncate the body. Are these hard things to do? If not, could you help me or point me in the right direction for some help? Thank you!

  4. Dan on May 7th, 2009 8:38 am

    For Dene:

    I’m sure there’s a way in the DVWP code to filter by [Today]-5, but I’m not sure how to do that in the XSLT. Another option is to add a calculated column to your QOTD list with this formula– =[Today]-5 –and have the column display the result as a Date. Then, in your DVWP, just do a conditional format to show the items only if they’re greater than the calculated column’s date.

Leave a Reply