17.1. Understanding the Basics of the Data Form Web Part

To understand the internals of the Data Form Web Part, follow these steps to insert a simple view of data by using the Data Form Web Part. Then, I help analyze the key components that make the Data Form Web Part work:

  1. Open a WSS v3 site in SharePoint Designer by using the Open Site dialog box to specify the location of the Web site. Alternatively, you can open the WSS v3 site in Internet Explorer and then choose File Edit with SharePoint Designer to open the site in SharePoint Designer.

  2. Choose File New Create from Master Page to open the Select a Master Page dialog box, click the Default Master Page radio button, and then click OK. This creates a new Web page with the default master page of the SharePoint site attached to it.

  3. Open the newly created Web page in the Design view and then hover over the body area of the Web page to locate the PlaceHolderMain content region. As shown in Figure 17.1, clicking the arrow in this region opens the Common Content Tasks menu.

  4. Click the Create Custom Content link in the Common Content Tasks menu to open the PlaceHolderMain content region for editing.

  5. Choose Data View Manage Data Sources to open the Data Source Library task pane.

  6. Expand the SharePoint Lists section, click any of the default lists, and then click Show Data. The Data Source Details task pane opens.

  7. Ensure that some columns of the list are selected and then choose Insert Selected Fields as Multiple Item View. The DataFormWebPart is inserted on the Web page.

With the Data Form Web Part selected in the Design view, if you click the Code view tab, a large chunk of highlighted code forms the HTML code for the Data Form Web Part. There are four major components of the Data Form Web Part: DataSources, ParameterBindings, DataFields, and XSL.

Figure 17.1. Finding the PlaceHolderMain content region in the Web page associated with the master page

17.1.1. DataSources

The <DataSources> tag inside the DataFormWebPart specifies the data source control that the DataFormWebPart uses for interfacing with the SharePoint data source. As represented by the following code, the data source control used by the DataFormWebPart for SharePoint lists is the SharePoint:SPDataSource:

<DataSources>
         <SharePoint:SPDataSource runat="server"
   DataSourceMode="List" UseInternalName="true"
   selectcommand="&lt;View&gt;&lt;/View&gt;" id="Announcements1">
   <SelectParameters><WebPartPages:DataFormParameter Name="ListID"
   ParameterKey="ListID" PropertyName="ParameterValues"
   DefaultValue="3B310B2C-F7C0-4BD9-82AA-92C6F302F15D"/></ SelectPar
   ameters><DeleteParameters><WebPartPages: DataFormParameter
   Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues"
   DefaultValue="3B310B2C-F7C0-4BD9-82AA-92C6F302F15D"/></
   SeleteParameters><UpdateParameters><WebPartPages:
   DataFormParameter Name="ListID" ParameterKey="ListID"

PropertyName="ParameterValues" DefaultValue="3B310B2C-F7C0-4BD9-82AA-
   92C6F302F15D"/></DeleteParameters><UpdateParameters><WebPartPages:
   DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName=
   "ParameterValues" DefaultValue="3B310B2C-F7C0-4BD9-82AA-
   92C6F302F15D"/></InsertParameters></SharePoint:SPDataSource>
   </DataSources>

The DataSourceMode property specifies the scope of the data source and the selectcommand provides the Collaborative Application Markup Language (CAML) query to retrieve data from the SharePoint list. The <SelectParameters>, <DeleteParameters>, <UpdateParameters>, and <InsertParameters> tags provide the select, delete, update, and insert parameters when required.

17.1.2. ParameterBindings

This section of the DataFormWebPart code specifies how parameters in the DataFormWebPart should be bound to the various sources of data. As shown in the following code, the Name attribute specifies the name of the parameter and the Location attribute indicates the source of data for the parameter:

<ParameterBindings>
      <ParameterBinding Name="ListID" Location="None"
DefaultValue="3B310B2C-F7C0-4BD9-82AA-92C6F302F15D"/>
      <ParameterBinding Name="dvt_apos" Location="Postback;Connection"
/>
      <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultV
alue="CurrentUserName"/>
      <ParameterBinding Name="Today" Location="CAMLVariable"
DefaultValue="CurrentDate"/>
</ParameterBindings>

SharePoint provides the following values for the Location attribute:

  • PostBack: Indicates that the value of the parameter is sustained between page refreshes

  • Connection: Indicates that the source of data for the parameter could be from another Web part

  • Query String: Indicates that the value of the parameter can come from a query string

  • CAMLVariable: Indicates that the source of data for the parameter could be a CAML variable specified in the SharePoint code

  • SSOTicket: Indicates that the source of data for the parameter could form an SSO connection

17.1.3. DataFields

The DataFields section of the DataFormWebPart code specifies the fields of data available for use inside the DataFormWebPart. Here is an excerpt of the code from the previous exercise:

<datafields>@ID,ID;@ContentType,Content Type;@Title,Title;@
   Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified

By;@_UIVersionString,Version;@Attachments,Attachments;@File_
         x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@
         FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has
         Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content
         Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI
         Version;@Created_x0020_Date,Created;@FileRef,URL Path;@
         Body,Body;@Expires,Expires;</datafields>

As indicated in this code, the <datafields> tag lists all the available columns with their internal and actual names. The internal names are used later in the XSL section.

17.1.4. XSL

The <XSL> property encapsulates the display functionality of the DataFormWebPart. The most elegant feature of the Data Form Web Part is that it uses Extensible Stylesheet Language (XSL) transformations to transform XML data received from the data source control discussed previously for display purposes. Most of the SharePoint Designer user interface for the Data Form Web Part is concentrated on providing abilities to modify this XSL code to implement advanced filtering, sorting, grouping, paging, formatting, and styling. If you're XSL-savvy, you can only imagine the amount of control the Data Form Web Part provides to work with the data from SharePoint data sources.

Highlighted in the following code are some of the important pieces to understand the XSL implementation of the Data Form Web Part. Each XSL template performs some transformation and then calls another template to proceed with the transformation. For example, the dvt_1 calls the dvt_1.body, which in turn calls the dvt_1.rowview.

<XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
   xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
   version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
   xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/
   runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
   xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/
   DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
   xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2=
   "urn:frontpage:internal">
   <xsl:output method="html" indent="no"/>
   <xsl:decimal-format NaN=""/>
   <xsl:param name="dvt_apos">&apos;</xsl:param>
   <xsl:variable name="dvt_1_automode">0</xsl:variable>
   <xsl:template match="/">
         <xsl:call-template name="dvt_1"/>
   </xsl:template>
   <xsl:template name="dvt_1">
         <xsl:variable name="dvt_StyleName">Table</xsl:variable>

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/
   Row"/>
         <table border="0" width="100%" cellpadding="2"
   cellspacing="0">
                <tr valign="top">
                       <xsl:if test="$dvt_1_automode = '1'"
   ddwrt:cf_ignore="1">
                              <th class="ms-vh" width="1%"
   nowrap="nowrap"></th>
                       </xsl:if>
                       <th class="ms-vh" nowrap="nowrap">ID</th>
                       <th class="ms-vh" nowrap="nowrap">Content
   Type</th>
                       <th class="ms-vh" nowrap="nowrap">Title</th>
                       <th class="ms-vh" nowrap="nowrap">Modified</
   th>
                       <th class="ms-vh" nowrap="nowrap">Created</
   th>
                </tr>
                <xsl:call-template name="dvt_1.body">
                       <xsl:with-param name="Rows" select="$Rows"/>
                </xsl:call-template>
         </table>
   </xsl:template>
   <xsl:template name="dvt_1.body">
         <xsl:param name="Rows"/>
         <xsl:for-each select="$Rows">
                <xsl:call-template name="dvt_1.rowview"/>
         </xsl:for-each>
   </xsl:template>
   <xsl:template name="dvt_1.rowview">
         <tr>
                <xsl:if test="position() mod 2 = 1">
                       <xsl:attribute name="class">ms-alternating</
   xsl:attribute>
                </xsl:if>
                <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_
   ignore="1">
                       <td class="ms-vb" width="1%" nowrap="nowrap">
                              <span ddwrt:amkeyfield="ID" ddwrt:amke
   yvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></
   span>
                       </td>
                </xsl:if>
                <td class="ms-vb">
                       <xsl:value-of select="format-number(@ID,
   '#,##0.#;-#,##0.#')"/>
                </td>
                <td class="ms-vb">

<xsl:value-of select="@ContentType"/>
                </td>
                <td class="ms-vb">
                       <xsl:value-of select="@Title"/>
                </td>
                <td class="ms-vb">
                       <xsl:value-of select="ddwrt:FormatDate(string
   (@Modified), 1033, 5)"/>
                </td>
                <td class="ms-vb">
                       <xsl:value-of select="ddwrt:FormatDate(string
   (@Created), 1033, 5)"/>
                </td>
         </tr>
   </xsl:template>
</xsl:stylesheet>
</XSL>

New XSL templates are added to this code when and as more formatting options are selected by using the user interface. Don't be let down if you're not comfortable with using XSLT, as the SharePoint Designer interface provides straightforward abilities to modify this XSL transformation without having in-depth understanding of XSLT and XPath expressions. This chapter familiarizes you with the SharePoint Designer user interface for manipulating the XSL code of the DataFormWebPart and thereby implementing formatting on data exposed by SharePoint data sources.

NOTE

When you insert a DataFormWebPart as a view of data, it's called the Data View. When you insert it as a form, it's called a Data Form. In both cases, the Web part is the same; just the rendering mode changes based on the XSL applied.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.154.172