Skip to main content

How to convert SharePoint Data View Web Part in dropdown format and display unique items or values.

These steps will guide you through the process of coverting the SharePoint Data View Web Part into dropdown format and display the unique items or values from the list. Now to perform the steps below, the SharePoint designer and XSL knowlegde is required.   

Start by adding a blank Data View Web Part on a page. Then attach the list source to the data view from data source library. For this example I will attach the test list that I created for this tutorial.After providing the source for the Data View all the columns from the list will be displayed. Now lets drag and drop one of the columns from the  data source on a Data View. At this point it will bring all the data from that column and display it in a table format. If it is previewed it will look like this :
 
Data View Web Part in Table Format


Now, lets convert this Data View Web Part into a drop down format. In a SharePoint designer click on the little arrow or bracket at top right corner of a Data View

Bracket at top right corner of a Data View






This will bring the menu for that Data View

Data View Menu

 From this menu click on "Data View Properties" and it will open the properties window.

Now on this window click on "Layouts" tab and scroll all the way to the bottom to select the dropdown layout. After selecting it click "OK".  









Save the page and preview it. At this point it should appear like :











In the above screenshot all the items from the column are being displayed in a dropdown and there two items that are duplicate : "Chicago" & "California". Now we will go ahead and modify the XSL of a Data View to only display the unique values.

Look for the following XSL code in a Data View

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


Create a xsl variable, in this case it is "uniqueState" :
<xsl:variable name="uniqueState" select="@Test"/>


Modify the above XSL code to :

<xsl:if test="generate-id()=generate-id(//Rows/Row[@Test=$uniqueState][1])">   
       <option>
                 <xsl:value-of select="@Test" />
       </option>

</xsl:if>

Full modified XSL code:

<xsl:template name="dvt_1.rowview">
    <xsl:variable name="uniqueState" select="@Test"/>
     <xsl:if test="generate-id()=generate-id(//Rows/Row[@Test=$uniqueState][1])">   
            <option>
                   <xsl:value-of select="@Test" />
            </option>

     </xsl:if>
</xsl:template>


After implemeting the above code the dropdown will look like :


 







Comments

Post a Comment

Popular posts from this blog

Returning selected value from Dropdown Box using JavaScript

Below is the example for returning value of the selected item in a Dropdown box: HTML Dropdown control or element with the id “test”              <select id="test" onchange="getVal();">                   <option value="1">1</option>                   <option value="2">2</option>                   <option value="3">3</option>            </select> JavaScript function for getting the selected value from dropdown: ·   First get the selected index from the dropdown and store it in a variable.        var ddIndex = document.getElementById("test...