Wednesday, 24 June 2009


One of the most important part in SharePoint is displaying the content without
braking any SharePoint features.

In this scenario DataFormWebPart is our guidance. There are always other ways to
display the content like custom webparts/webpartpages, but developing with these
methods may cost us lots of time.

In the following example we will learn how to develop a simple DataFormWebPart.

This is the syntax we will work on it.

<WebPartPages:DataFormWebPart id="TasksDisplayDataFormWebPart" runat="server"
FrameType="None" NoDefaultStyle="TRUE" ViewFlag="1" Title="Tasks"
DisplayName="Tasks" __markuptype="vsattributemarkup"
__WebPartId="{418745AA-67C6-481e-95F9-5C824AD0CE61}" WebPart="true">


<SharePointWebControls:SPDataSource runat="server" DataSourceMode="List"
UseInternalName="true" selectcommand="<View/>" id="SPDataSource1">


<webpartpages:DataFormParameter Name="ListName" ParameterKey="ListName"
PropertyName="ParameterValues" DefaultValue="Tasks"/>





<ParameterBinding Name="ListName" Location="None" DefaultValue="Tasks" />

<ParameterBinding Name="dvt_apos" Location="Postback;Connection" />

<ParameterBinding Name="UserID" Location="CAMLVariable"
DefaultValue="CurrentUserName" />

<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate" />

<ParameterBinding Name="WebPartTitle" Location="None" DefaultValue="{Title}" />

<ParameterBinding Name="WebPartTitleURL" Location="None" DefaultValue="{TitleUrl}" />



<XslLink>/Style Library/XSL Style Sheets/SPTest/FullContent.xsl</XslLink>

</WebPartPages:DataFormWebPart >

Now let’s have a look at the properties;

a) DataSources: This defines where the data to get from We have some controls to
get the data, here is some of them;

i) SPDataSource: Gets the data from single or multiple (cross, we
will mention it in later blogs) SharePoint libraries content.


• List: Retrieves
data from a list

• ListItem: Retrieves
data from a single list item

• CrossList:
Retrieves data from multiple lists in multiple websites in the same site

• ListOfLists:
Retrieves properties of lists in a specified web site.

• Web: Retrieves
properties of subsites of the current web site.

SelectCommand: This is where we define our
query to get data. CAML is the query syntax. Custom parameters such as
QueryString, existing variables, programmatically defined
parameterbindings can be used, but it will be shown on feature blogs.

SelectParameters: That is used to define to
pass parameter binding values and also other type of parameters.

ii) SPXmlDataSource:

<SharePoint:SPXmlDataSource runat="server">


<WebPartPages:DataFormParameter Name="FileName" ParameterKey="FileName"
PropertyName="ParameterValues" DefaultValue="items.xml"/>

<WebPartPages:DataFormParameter Name="FilePath" ParameterKey="FilePath"
PropertyName="ParameterValues" DefaultValue=""/>



b) ParameterBindings: To supply user defined or environment defined values to
the actual query.

c) DataFields: Fields those are used in xsl.

d) XSLLink: Xsl file to display content in a custom format.

Sample of the following code xsl;

<xsl:stylesheet xmlns:x=""
xmlns:d="" version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"

<xsl:output method="html" indent="no"/> <xsl:decimal-format NaN=""/>

<xsl:param name="dvt_apos">'</xsl:param>

<xsl:param name="WebPartTitle">


<xsl:param name="WebPartTitleURL"></xsl:param> <xsl:variable

<xsl:template match="/">

<xsl:call-template name="dvt_1"/> </xsl:template>

<xsl:template name="dvt_1">

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>

<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">


<xsl:call-template name="dvt_1.body">

<xsl:with-param name="Rows" select="$Rows"/>



<xsl:template name="dvt_1.body">

<xsl:param name="Rows"/>

<xsl:for-each select="$Rows">

<xsl:call-template name="dvt_1.rowview"/>



<xsl:template name="dvt_1.rowview"> Title: <xsl:value-of select="@Title"/><br/>




  1. This comment has been removed by the author.

  2. HI, good info... thanks..

    is there any way to get the "Webpart Title" using the XSLT in Content Query Webpart.

    I can get the PageUrl and Webpart Id using parameters
    xsl:param name="PageUrl" /
    xsl:param name="WebPartId" /

    but could not get any of the webpart properties, where I am specifically looking to get the "Web Part Title URL" and "Web part Title"
    as i have Links in the webpart Body that will link based on values in these two properties.

    please, please let me know if you have anywork around to get the webpart Title URL and WEbpart Title using XSl from any of the xsl files out there in sharepoint[contentquerymain.xsl, Itemstyle.xsl, Header.xsl]..

    Thank you.

  3. Check this post please, It explains how you can get those properties.

  4. that was helpful .
    I could easily get a DataFormWebPart deployed with custom list def in first go.