Search code examples
sharepointxsltsharepoint-2007sharepoint-designer

How to bind a SharePoint textfield to a dropdownlist?


I'm customizing a custom list form in xslt using SharePoint designer. In my list, I have a textbox that represents a numerical value.

I would like to present this textbox to the user as a dropdown list with pre-defined values (1-7). Unfortunately, I can't use a SPFieldChoice because it is evaluated as a string in my SharePoint Designer Workflow and there aren't any built-in conversions.

I'm hoping that I could simply define an asp DropDownList control and use the ddwrt:DataBind syntax, but the following isn't working.

<asp:DropDownList id="ddlValue" runat="server" 
   __designer:bind="{ddwrt:DataBind('i', 'ddlValue', 
                    'SelectedValue', 'OnSelectedIndexChanged', 'ID',
                     ddwrt:EscapeDelims(string(@ID)),'@MyField')}">
   <asp:ListItem value="1" selected="true">1</asp:ListItem>
   <asp:ListItem value="2">2</asp:ListItem>
   <asp:ListItem value="3">3</asp:ListItem>
   <asp:ListItem value="4">4</asp:ListItem>
   <asp:ListItem value="5">5</asp:ListItem>
   <asp:ListItem value="6">6</asp:ListItem>
   <asp:ListItem value="7">7</asp:ListItem>    
</asp:DropDownList>

The selected value "1" does get saved with the item when it's created, so it is picking up the databinding. However, if I select any other value, it still records "1".

Is the syntax wrong, or is there a better way?

What would you do?


Solution

  • Looks like my binding syntax is wrong. Changing it to use the TextChanged event instead of OnSelectedIndexChanged.

    The following appears to work:

     __designer:bind="{ddwrt:DataBind('i', 'ddlValue',
                       'SelectedValue, 'TextChanged', 'ID'
                       ddwrt:EscapeDelims(string(@ID), '@MyField')}"