Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
Visual How Tos
 Customizing SharePoint List Views w...
Community Content
In this section
Statistics Annotations (7)
Customizing SharePoint List Views with SharePoint Designer 2007

Summary: Learn how to use Microsoft Office SharePoint Designer to customize the Data Form Web Part. You can display SharePoint list data and filter the data by using an ASP.NET drop-down list control.

Office Visual How To

Applies to:   Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007, Microsoft Office SharePoint Designer 2007

Anup Kafle, 3Sharp

February 2008

Overview

Windows SharePoint Services 3.0 ships with a powerful and feature-laden Web Part named the Data Form Web Part (DFWP), which can present data from a wide array of data sources such as external databases, business data catalogs, and SharePoint lists. The DFWP is a new and improved version of the Data View Web Part (DVWP) that was included with Windows SharePoint Services 2.0. Because of this connection, the names "Data Form Web Part" and "Data View Web Part" are still used interchangeably.

The DFWP uses ASP.NET 2.0 data source controls for data access. (See ASP.NET Quickstart Tutorials for more information on data source controls.) When used with ASP.NET controls in Microsoft Office SharePoint Designer 2007, this Web Part can become a highly flexible and customizable tool for presenting data to the user interface. This Visual How To illustrates how you can customize the DFWP in Office SharePoint Designer 2007 to display SharePoint list data and filter the data by using an ASP.NET drop-down list control. Despite being an ASP.NET control itself, using the DFWP in Office SharePoint Designer 2007 is essentially a code-free experience.

Code It

This scenario involves a Windows SharePoint Services 3.0 site with a task list that is prepopulated with some sample data. The possible priority values are (1) High, (2) Normal, and (3) Low. The goal is to present the task list data in a DFWP and filter the data by priority.

To insert a DFWP

  1. Start Office SharePoint Designer 2007.

  2. Click File, click Open Site, and open the site that contains the task list.

  3. Double-click default.aspx to open it for editing.

  4. Click within the Web Part zone where you want to add the DFWP.

  5. Click Data View, and then click Insert Data View.

This procedure inserts a DFWP in the selected Web Part zone in the default.aspx page. Office SharePoint Designer 2007 also displays the Data Source Library task pane to the right.

Now use the Data Source Library task pane to connect the DFWP with the task list.

To display task data in the DFWP

  1. In the task pane, expand the SharePoint Lists category.

  2. Right-click Tasks, and click Show Data. This action displays the Data Source Details task pane.

  3. Select the following fields (by using CTRL+left-click): Title, Priority, Status, % Complete, and Assigned To.

  4. Click the Insert Selected Field as list, and click Multiple Item View. (See Figure 1.)

    Figure 1. Data Source Details task pane
    Data Source Details task pane

    The DFWP displays all rows of data in the task list.

The layout of this data is controlled by XSLT markup behind the Web Part. Although you can manually modify this XSLT markup by switching to the code view in Office SharePoint Designer 2007, you can achieve a number of key formatting operations without any coding. For example, you can apply custom number formatting to the % Complete values by using the Common Tasks menu in Office SharePoint Designer 2007.

To modify the number format of the % Complete field

  1. Hover over a data value in the % Complete column.

  2. Click the > button, located to the right of the data value, to display the Common Tasks menu.

    Figure 2. Common Tasks menu for data field formatting
    Common Tasks menu for data field formatting
  3. Click Number formatting options.

  4. In the Format Number dialog box, click Percentage(%), and click OK.

    The numeric values in the % Complete column are now formatted as percentage values.

The DFWP can accept parameters that can be used to filter data. In this example, you pass the filter parameter from a drop-down list control. First, you create the drop-down list control.

To add a drop-down list control filter to the Web Part

  1. While in design view in Office SharePoint Designer 2007, place the cursor in the top area outside the Web Part zone.

  2. Switch to the Data Source Library task pane.

  3. Right-click Tasks, and click Insert Data Source Control. This action inserts an SPDataSource object with the default ID spdatasource1.

  4. Click Insert, point to ASP.NET Controls, and click Dropdown List.

  5. In the Common DropDownList Tasks menu, select the Enable AutoPostBack check box.

  6. In the same menu, click Choose Data Source.

  7. In the Data Source Configuration Wizard, select the following options:

    • Select a data source: spdatasource1

    • Select a data field to display in the DropDownList: Priority

    • Select a data field for the value of the DropDownList: Priority

  8. Click OK.

You have created a drop-down list control and set it up to display the task priority values. The next step is to configure the data view so that it filters rows based on the selection in the drop-down list control.

To configure the data view to accept filter parameters

  1. Click the > button in the top-right corner of the Web Part to display the Common Data View Tasks menu.

  2. In the Common Data View Tasks menu, click Filter.

  3. In the Filter Criteria dialog box, click Click here to add a new clause.

  4. Fill in the values as follows:

    • Field Name: Priority

    • Comparison: Equals

    • Value: Create a new parameter

  5. In the Data View Parameters dialog box, fill in the values as follows:

    • Name: Priority

    • Parameter Source: Control

    • Control ID: DropDownList1

    • Default Value: (1) High

    Figure 3. New data view parameter
    New data view parameter
  6. Click OK in the Data View Parameters and Filter Criteria dialog boxes.

At this point, the basic Web Part configuration is complete. Save the page and open it in a browser. You can see the drop-down list control above the DFWP.

Figure 4. DFWP with a drop-down list control filter
DFWP with a drop-down list control filter Read It

In this Visual How To, you saw how you can filter a list that is displayed in a DFWP by using an ASP.NET drop-down list control. The filter value is passed to the Web Part as a parameter. Other ASP.NET controls, such as a text box or an option button, can also be used as filter controls to pass parameters. The Web Part can also accept parameters from other sources, such as a URL (referred to as a Query String in the Data View Parameters dialog box), cookie, custom form field, and server variable. Each type of parameter can accept a default value.

Notice that you place the drop-down list control outside the Web Part zone, although the DFWP itself was inside the zone. This is because Windows SharePoint Services appends the Web Part zone GUID to the ID of any control that is placed within the Web Part zone at run time. Instead of a simple ID, such as DropDownList1, you get something similar to ctl00_m_g_0e4ece69_4898_4dfd_8938_9bc477b43786_DropDownList1.

The WYSIWYG interface of SharePoint Designer enables you to achieve this solution with no coding. The extensive set of wizards, templates, interactive task panes, and context menus in SharePoint Designer provide a rich user interface for customizing Web Parts. Although you can use any editor that is compatible with Windows SharePoint Services or the WebDAV protocol to customize SharePoint pages, you are limited to the code view of the pages. SharePoint Designer allows you to edit in code view as well as design view. Actually, as you customize a page in design view, as in this Visual How To, SharePoint Designer generates the underlying code on the fly, which is viewable in code view. Because the code is a mix of HTML, ASPX, and XSLT markups, you can also edit the code yourself directly while taking advantage of IntelliSense provided by SharePoint Designer. In fact, using the design view in SharePoint Designer to perform basic tasks and then switching to code view to fine-tune the customizations is a common best practice for customization in Windows SharePoint Services.

See It Customizing SharePoint List Views

Watch the Video

Video Length: 00:07:27

File Size: 13.9 MB WMV

Explore It
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Video shows non-unique entries in the filter      Paul Galvin ... robpiolink   |   Edit   |   Show History
It would have been nice if the presenter addressed the fact that the dropdownlist filter control shows "(2) Normal" many times. End users would not accept that. They would expect there to be just a single entry for each type of priority.
Paging do not work correctly when dataview is connected      vipul1969 ... Thomas Lee   |   Edit   |   Show History
Everything works fine until paging is enabled on the dataview after connetion. The problem occurs after once clicking on the paging buttons and then clicking on the dropdownlist to do a new selection. Page nos are displayed even if there are no match found or wrong paging is shown.
Re: Video shows non-unique entries in the filter      robpiolink   |   Edit   |   Show History

do we get an answer how to filter dropdownlist control so int only shows unique entry?

Re: Video shows non-unique entries in the filter      epact ... Thomas Lee   |   Edit   |   Show History

Anyone have an answer to the dropdownlist control not displaying unique entries?

[tfl - 07 05 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio  : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public     : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
Re: Video shows non-unique entries in the filter      XristosK   |   Edit   |   Show History

In order to have unique values, you have to use XSLT 1.0 and use the Muenchian method. Google the "Grouping Using the Muenchian Method" and go to jenitennison.com.

Tags What's this?: Add a tag
Flag as ContentBug
Is it work for Date time fields?      PraveenBattula ... Thomas Lee   |   Edit   |   Show History
Hi,

when i followed the post, i observed that it was working for all the data types except date time fields.

For example,

i populated the drop down with the "created" column in my list. and created a parameter for the data form web part, which takes the selected value from the drop down.

it's not working at all. but if i changed the value to "Title" or other fields which is not a date time type, it is working as expected.

please help me out. is this a general issue or any thing wrong from side?

thanks

-Praveen.

[tfl - 07 05 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio  : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public     : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
Doubt regarding the DropDownList      sudharsank ... Thomas Lee   |   Edit   |   Show History

As per the above procedure i have added the dropdown list and assigned the proper spdatasource. But the dropdownlist is filled with the items from the list i.e., more than one "(3) Low" and "(1) High" value. Please any one help me with this...

Thanks

K.Sudharsan...

[tfl - 07 05 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker