Wednesday, May 9, 2012

Using SPDataSource and DVDropDownList For Filtered Dropdowns

   1: <tr>
   2:      <td width="190px" valign="top" class="ms-formlabel">
   3:            <H3 class="ms-standardheader"><nobr>Status</nobr></H3>
   4:      </td>
   5:      <td width="400px" valign="top" class="ms-formbody">
   6:            <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="True" ID="spdatasource1" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;CurrentState&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;{@TestProgramStatus}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;FieldRef Name=&quot;AllowedState&quot;/&gt;&lt;FieldRef Name=&quot;DisplayText&quot;/&gt;&lt;/ViewFields&gt;&lt;/View&gt;" >
   7:                <SelectParameters>
   8:                     <asp:Parameter Name="WebID" DefaultValue="RootWeb" />
   9:                     <asp:parameter Name="ListID" DefaultValue="3C594A44-184E-4B4B-B6D4-5B26F958C5F5" />
  10:                </SelectParameters>
  11:            </SharePoint:SPDataSource>              
  12:            <SharePoint:DVDropDownList runat="server" title="ddStatus" id="ff3{$Pos}" selectedvalue="Select Status" __designer:bind="{ddwrt:DataBind('u',concat('ff3',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@TestProgramStatus')}" datasourceid="spdatasource1" datatextfield="DisplayText" datavaluefield="AllowedState" /><br />                                
  13:            <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="TestProgramStatus" ControlMode="Edit"/>
  14:      </td>
  15: </tr>

This code was added to a custom form in SharePoint Designer. The code is in the XSL stylesheet and this was created to filter a Status Choice field based on its current status. The SelectCommand was used to do the filtering and it is just encoded CAML. This query checks the current status against a separate list that contains the "allowed" status values for the current status. This is used to drive an item through a certain process. A user can select a status but the choices are limited depending on where the item is in the process. The list also has a display text so the dropdown has a more descriptive text of what the user is selecting. The DVDropDownList then updates the actual status field which is a choice field in this case.


  1. Hey mate, this might just be the exact thing I'm looking for and if so it'd be a total life saver.

    How did you enconde your CAML?

    1. I found where to encode the CAML.

      For my part, I was actually trying to link two DVListBox, one was to be filtered by the selected value in the other. I tried putting the field name ({@FieldName}) but this doesn't give me dynamic filtering which is what I'm desperately looking for.

      Still, your post shed some lite into the problem, thanks.

  2. Hey Fabian,
    I have the same problem, but I am trying to filter DVDropDownList based on the selction made in another DVDropDownList. Could you please tell me how did you reference the list within the CAML query, so that you filtered the second list based on the selection in the first?

    1. Hi Botty, did you get the solution about the dvdropdownlist in cascade? I need to do the same, I can get the the second dvdropdownlist with the result filtered by a parameter, but now I need to pass the value from the selection of the first dvdropdownlist to the parameter. Any ideas?