- Open up an existing DVWP or create one.
- Right click the DVWP and select ‘Common Data View Tasks’ (or click the little arrow that appears on the top right of the DVWP)
- Click the ‘Parameters’ link
- In the dialog that opens up click the ‘New Parameter’ button.
- Provide a name for the parameter (e.g. IPAddress)
- In the ‘Parameter Source’ dropdown select ‘Server Variable’
- In the ‘Server Variable Name’ text box enter REMOTE_ADDR
- Leave the ‘Default Value’ text box empty
- Click OK
- Now switch to the code view and go to the place where you want the IPAddress to appear and type the following:
<xsl:value-of select="$IPAddress" />
Here’s a list of server variables:
I have a list with a column called newsID. newsID is a calculated column based on created date. I set the column as a number type and leave the decimal places to be automatic.
This list also have another calculated column called newsLink. newsLink is calculated based on newsID.
I have a Data View Web Part to display a item from this list. The DVWP has a parameter and filters based on the newsID column.
Once all of these are setup, open the DVWP in browser. Copy one of the list item’s newsID value to the end of that page’s URL. The item should display fine in the DVWP page.
Edit that item in the list. Refresh the DVWP page. Oops! You see the message “There are no items to show in this view.”
Change the newsID column to have this formula:
Select data type to be Single line of text.
Issue should be fixed.
Add DVWP to web part page
- Open the site that contains the list/library that you need in SharePoint Designer.
- Navigate to “All Files”. Create a folder which will be used to store web part pages.
- Open the folder. Click “Web Part Page” button on the ribbon.
- Choose one of the layouts. Enter a name. Notice the file is actually saved to Site Pages folder. So don’t panic if you don’t see it. Go to “Site Pages” from the left Navigation Pane and cut and paste the page to the folder you created in step 2.
- Next, we are going to add the DVWP to the web part page. Click on one of the web part zones. Click “Insert” tab from ribbon->Data View->Empty Data View
- In the zone, click “click here to select datasource” to select the datasource or list.
- From the “Data Source Picker”, select the interested List or Library.
- All the available fields of the selected list or library will be listed in the Data Source Details pane on the right side.
- Drag the fields that you want to display to the web part.
- To add more columns or rows to the DVWP, click the Table tab on the ribbon and select relevant options.
- To add a horizontal rule, highlight the cell, the code will be highlighted in code view, enter <hr />. For example, <td colspan=”5″ /><hr/></tr>
Tips: For columns that displays raw html code, add disable-output-escaping=”yes” For example, <xsl:value-of select=”@Comments” disable-output-escaping=”yes”/>
Grouping, Sorting and Paging in DVWP
For grouping and sorting, click the web part and choose Options->Sort & Group in the ribbon.
For paging, click the web part and choose Options->Paging in the ribbon.
Filters and Parameters in DVWP
To filter on a column, simply click Filter.
To use a Query String, there are multiple steps as below.
- Click Options->Parameters->New Parameter. Select “Query String” from Parameter Source. Query String Variable is used in the URL, e.g. agdocs/stakeholder.aspx?ParaVar=ParaValue. Give a Default Value if you have one. Then click OK.
- Go to Options->Filter. Choose the field that is based on the parameter value.
- Save the page and open in browser. Items with Team value of Director & Support will be displayed as it’s the default value. In the URL, type ?Team=Portfolio Team to the end of the URL, items with Team value of Portfolio Team are displayed.
Export Web Part