Sample DataView Webpart for SharePoint Designer 2010


/ Published in: VB.NET
Save to your folder(s)

Sample DataView Webpart for SharePoint Designer 2010 demonstrating adding the WebURL parameter and renaming listID to listName.


Copy this code and paste it in your HTML
  1. <WebPartPages:DataFormWebPart runat="server" Description="" ListDisplayName="" PartOrder="4" HelpLink="" AllowRemove="True" IsVisible="True" AllowHide="True" UseSQLDataSourcePaging="True" ExportControlledProperties="True" DataSourceID="" Title="N6 Staff" ViewFlag="8" NoDefaultStyle="TRUE" AllowConnect="True" FrameState="Normal" PageSize="-1" PartImageLarge="" AsyncRefresh="False" ExportMode="All" Dir="Default" DetailLink="" ShowWithSampleData="False" ConnectionID="00000000-0000-0000-0000-000000000000" AllowZoneChange="True" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{81D4C1D7-8202-4C51-8888-1D407293AE04}" __AllowXSLTEditing="true" WebPart="true" Height="" Width="400px"><ParameterBindings>
  2. <ParameterBinding Name="ListName" Location="None" DefaultValue="CSG10 Staff"/>
  3. <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
  4. <ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
  5. <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
  6. <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
  7. </ParameterBindings>
  8. <DataFields>@Title,Staff Name;@JobTitle,Title;@Rank,Rank;@N_x002d_Code,N-Code;@Department,Department;@WorkPhone,Business Phone;@Email_x0020__x0028_Unclass_x0029,Email;@Number,Number;@Name_x0020__x0026__x0020_Rank,Name &amp; Rank;@ID,ID;@ContentType,Content Type;@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;@ItemChildCount,Item Child Count;@FolderChildCount,Folder Child Count;</DataFields>
  9. <Xsl>
  10. <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">
  11. <xsl:output method="html" indent="no"/>
  12. <xsl:decimal-format NaN=""/>
  13. <xsl:param name="dvt_apos">'</xsl:param>
  14. <xsl:param name="ManualRefresh"></xsl:param><xsl:variable name="dvt_1_automode">0</xsl:variable>
  15. <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
  16. <xsl:choose>
  17. <xsl:when test="($ManualRefresh = 'True')">
  18. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  19. <tr>
  20. <td valign="top">
  21. <xsl:call-template name="dvt_1"/>
  22. </td>
  23. <td width="1%" class="ms-vb" valign="top">
  24. <img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/>
  25. </td>
  26. </tr>
  27. </table>
  28. </xsl:when>
  29. <xsl:otherwise>
  30. <xsl:call-template name="dvt_1"/>
  31. </xsl:otherwise>
  32. </xsl:choose>
  33. </xsl:template>
  34. <xsl:template name="dvt_1">
  35. <xsl:variable name="dvt_StyleName">Table</xsl:variable>
  36. <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
  37. <xsl:variable name="dvt_RowCount" select="count($Rows)"/>
  38. <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
  39. <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
  40.  
  41. <xsl:choose>
  42. <xsl:when test="$dvt_IsEmpty">
  43. <xsl:call-template name="dvt_1.empty"/>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <table border="0" width="100%" cellpadding="2" cellspacing="0">
  47. <tr valign="top">
  48. <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
  49. <th class="ms-vh" width="1%" nowrap="nowrap"></th>
  50. </xsl:if><th class="ms-vh" nowrap="nowrap" style="font-family: Verdana, Helvetica, sans-serif; font-weight: normal; color: #003759; text-decoration: none">Position/Billet</th><th class="ms-vh" nowrap="nowrap">Name</th><th class="ms-vh" nowrap="nowrap">Phone</th></tr>
  51. <xsl:call-template name="dvt_1.body">
  52. <xsl:with-param name="Rows" select="$Rows"/></xsl:call-template>
  53. </table>
  54. </xsl:otherwise>
  55. </xsl:choose></xsl:template>
  56. <xsl:template name="dvt_1.body">
  57. <xsl:param name="Rows"/><xsl:for-each select="$Rows">
  58. <xsl:call-template name="dvt_1.rowview" />
  59. </xsl:for-each>
  60. </xsl:template>
  61. <xsl:template name="dvt_1.rowview">
  62. <tr>
  63. <xsl:if test="position() mod 2 = 1">
  64. <xsl:attribute name="class">ms-alternating</xsl:attribute>
  65. </xsl:if><td class="ms-vb">
  66. <xsl:value-of select="@JobTitle" /></td><td class="ms-vb" width="150">
  67. <xsl:value-of select="@Name_x0020__x0026__x0020_Rank" /></td><td class="ms-vb" width="100">
  68. <xsl:value-of select="@WorkPhone" /></td><xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
  69. <td class="ms-vb" width="1%" nowrap="nowrap">
  70. <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
  71. </td>
  72. </xsl:if>
  73. </tr>
  74. </xsl:template>
  75. <xsl:template name="dvt_1.empty">
  76. <xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
  77. <table border="0" width="100%">
  78. <tr>
  79. <td class="ms-vb">
  80. <xsl:value-of select="$dvt_ViewEmptyText"/>
  81. </td>
  82. </tr>
  83. </table>
  84. </xsl:template></xsl:stylesheet></Xsl>
  85. <DataSources>
  86. <SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;Department&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;6 - Communications&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Number&quot; Ascending=&quot;TRUE&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" UseServerDataFormat="True" ID="dataformwebpart1"><SelectParameters><WebPartPages:DataFormParameter ParameterKey="WebURL" PropertyName="ParameterValues" DefaultValue="/sites/csl/csg10" Name="WebURL"></WebPartPages:DataFormParameter><WebPartPages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="CSG10 Staff" Name="ListName"></WebPartPages:DataFormParameter>
  87. </SelectParameters>
  88. </SharePoint:SPDataSource>
  89. </DataSources>
  90. </WebPartPages:DataFormWebPart>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.