<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Antonio Gaetani</title><subtitle type="html" /><id>https://www.infopathdev.com:443/blogs/antonio/atom.aspx</id><link rel="alternate" type="text/html" href="https://www.infopathdev.com:443/blogs/antonio/default.aspx" /><link rel="self" type="application/atom+xml" href="https://www.infopathdev.com:443/blogs/antonio/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.31118.962">Community Server</generator><updated>2006-10-30T16:40:00Z</updated><entry><title>Update a Triggered Table</title><link rel="alternate" type="text/html" href="https://www.infopathdev.com:443/blogs/antonio/archive/2006/12/08/Update-a-Triggered-Table.aspx" /><id>https://www.infopathdev.com:443/blogs/antonio/archive/2006/12/08/Update-a-Triggered-Table.aspx</id><published>2006-12-08T20:44:00Z</published><updated>2006-12-08T20:44:00Z</updated><content type="html">&lt;p&gt;Querying and submitting to a database is a common scenario using InfoPath. In fact, it is very easy to develop a solution by designing a form from a SQL Server data connection, and then dropping the desired fields from Data Source task pane into the view. Then we can query the database and modify the desired records, or create and fill in a new record to submit to the database.&lt;/p&gt;&lt;p&gt;Following is an example of a form based on Employees table of the Northwind database:&lt;/p&gt;&lt;p&gt;&lt;img height="623" src="http://cs.infopathdev.com/photos/blog_pictures/images/324/original.aspx" style="width:598px;height:623px;" width="598" /&gt;&lt;/p&gt;&lt;p&gt;While connecting to a database is quite simple, suppose you want to add a simple insert or update trigger to the database table to identify whether &lt;font face="Courier New"&gt;LastName &lt;/font&gt;is unique:&lt;/p&gt;&lt;p&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;CREATE TRIGGER [Surname Check] ON [dbo].[Employees]&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;FOR INSERT, UPDATE&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;AS&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;update employees&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;set LastName = LastName + &amp;#39; (not unique)&amp;#39;&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;where LastName in&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select LastName&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from employees&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by LastName&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having count(*) &amp;gt; 1)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;But now, if we attempt to add an employee with a non-unique &lt;font face="Courier New"&gt;LastName &lt;/font&gt;(e.g. &amp;ldquo;Davolio&amp;rdquo;) we get the following error message:&lt;/p&gt;&lt;p&gt;&lt;img height="103" src="http://cs.infopathdev.com/photos/blog_pictures/images/325/original.aspx" style="width:658px;height:103px;" width="658" /&gt;&lt;/p&gt;&lt;p&gt;Clicking Show Details on this error message reveals that the information on primary key are not sufficient, because there are too many rows affected by the update. While we might be adding just one row, the trigger could update more than one row. InfoPath catches that the total number of rows affected by the modification does not match what it expected, and concludes that the information on the primary key is not enough. Because of this, the solution fails. What we need to do is disable the trigger&amp;rsquo;s &lt;font face="Courier New"&gt;count &lt;/font&gt;option, so that the total number of modifications returned from the database is equal to the number of rows submitted from InfoPath. This is easy to do using the &lt;font face="Courier New"&gt;nocount &lt;/font&gt;command.&lt;/p&gt;&lt;p&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;CREATE TRIGGER [Surname Check] ON [dbo].[Employees]&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;FOR INSERT, UPDATE&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;AS&lt;br /&gt;&lt;/font&gt;&lt;font color="#ff0000" face="Courier New" style="font-size:10pt;"&gt;set nocount on&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;update employees&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;set LastName = LastName + &amp;#39; (not unique)&amp;#39;&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;where LastName in&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select LastName&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from employees&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by LastName&lt;br /&gt;&lt;/font&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having count(*) &amp;gt; 1)&lt;br /&gt;&lt;/font&gt;&lt;font color="#ff0000" face="Courier New" style="font-size:10pt;"&gt;set nocount off&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;With this modification in place, it is now possible to add and update rows without errors. InfoPath correctly matches the total number of rows affected by the database as equal to the number of rows the form submitted.&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;br /&gt;Special thanks to my associate, Davide Tarfanelli, that spent his time with me to solve this task.&lt;/em&gt;&lt;/p&gt;&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=326" width="1" height="1"&gt;</content><author><name>Anonymous</name><uri>https://www.infopathdev.com:443/members/Anonymous.aspx</uri></author><category term="SQL" scheme="https://www.infopathdev.com:443/blogs/antonio/archive/tags/SQL/default.aspx" /><category term="nocount" scheme="https://www.infopathdev.com:443/blogs/antonio/archive/tags/nocount/default.aspx" /><category term="Trigger" scheme="https://www.infopathdev.com:443/blogs/antonio/archive/tags/Trigger/default.aspx" /></entry><entry><title>Dynamically Alter the Choices of a List Control</title><link rel="alternate" type="text/html" href="https://www.infopathdev.com:443/blogs/antonio/archive/2006/10/30/Dynamically-Alter-the-Choices-of-a-List-Control.aspx" /><id>https://www.infopathdev.com:443/blogs/antonio/archive/2006/10/30/Dynamically-Alter-the-Choices-of-a-List-Control.aspx</id><published>2006-10-30T22:40:00Z</published><updated>2006-10-30T22:40:00Z</updated><content type="html">&lt;p&gt;Have you ever found yourself wanting to bind the same control to different nodes? One solution to achieve the desired behavior is to create two controls with separate bindings and conditional visibility to hide and show them. This approach doesn&amp;#39;t work well for drop-down lists when you have numerous choices because it creates too many permutations of drop-down lists. Instead you can use the &lt;font face="Courier New"&gt;xdExtension&lt;/font&gt; prefix with code-behind to update the values. This article demonstrates how to use &lt;font face="Courier New"&gt;xdExtension&lt;/font&gt; to dynamically alter the choices in a list control.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Design the schema:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;To create a sample form to demonstrate this technique, we&amp;#39;ll need a sample schema. Copy and paste the the schema below into a text editor, and then save the file as &lt;strong&gt;FormSchema.xsd&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td align="left" style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;xsd:schema targetNamespace=&amp;quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-10-31T03:54:57&amp;quot; xmlns:my=&amp;quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-10-31T03:54:57&amp;quot; xmlns:xsd=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;xsd:element name=&amp;quot;Sample&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;TextField&amp;quot; type=&amp;quot;xsd:string&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;Set1&amp;quot; minOccurs=&amp;quot;0&amp;quot; maxOccurs=&amp;quot;unbounded&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;Set1Item&amp;quot; type=&amp;quot;xsd:string&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:element&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;Set2&amp;quot; minOccurs=&amp;quot;0&amp;quot; maxOccurs=&amp;quot;unbounded&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;Set2Item&amp;quot; type=&amp;quot;xsd:string&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:element&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name=&amp;quot;SelectedDataSource&amp;quot; type=&amp;quot;xsd:string&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsd:complexType&amp;gt;&lt;br /&gt;&amp;lt;/xsd:element&amp;gt;&lt;br /&gt;&amp;lt;/xsd:schema&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Create the sample form:&lt;/strong&gt;&lt;/p&gt;&lt;ol start="1" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Launch InfoPath.&lt;/li&gt;&lt;li&gt;Click Design A Form Template, and then click New From XML Document Or Schema.&lt;/li&gt;&lt;li&gt;In the Data Source Wizard, click Browse, locate and select the FormSchema.xsd file, click Open, and then click Next.&lt;/li&gt;&lt;li&gt;Select No for the question about whether to add another XML Schema, and then click Finish.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Add controls to the form:&lt;/strong&gt;&lt;/p&gt;&lt;ol start="1" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Open the Data Source Task Pane&lt;/li&gt;&lt;li&gt;Right-click &lt;em&gt;TextField&lt;/em&gt;, and then select Drop-Down List Box.&lt;/li&gt;&lt;li&gt;Right-click &lt;em&gt;SelectedDataSource&lt;/em&gt;, and then select Drop-Down List Box.&lt;/li&gt;&lt;li&gt;Right-click &lt;em&gt;Set1&lt;/em&gt;, and then select&amp;nbsp;Repeating Table.&lt;/li&gt;&lt;li&gt;Right-click &lt;em&gt;Set2&lt;/em&gt;, and then select&amp;nbsp;Repeating Table.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;You can add values to the Set1 and Set2 tables to test the form.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;To switch between data sources, we will use the &lt;font face="Courier New"&gt;SelectedDataSource&lt;/font&gt; drop-down list. You will have to manually add two entries (see picture below), one with the value &lt;strong&gt;1&lt;/strong&gt; and display name &lt;strong&gt;Set1&lt;/strong&gt;, and another with the value &lt;strong&gt;2&lt;/strong&gt; and display name &lt;strong&gt;Set2&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;img height="289" src="http://cs.infopathdev.com/photos/blog_pictures/images/320/original.aspx" style="width:408px;height:289px;" width="408" /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Establish the set of default values for the drop-down list:&lt;/strong&gt;&lt;/p&gt;&lt;ol start="1" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Right-click the TextField drop-down list box, and then choose Drop-Down List Box Properties.&lt;/li&gt;&lt;li&gt;Select Look Up Values In The Form&amp;#39;s Data Source.&lt;/li&gt;&lt;li&gt;Click the Select XPath button to the right of the Entries field.&lt;/li&gt;&lt;li&gt;Select &lt;em&gt;Sample/Set1/Set1Item&lt;/em&gt;, and then click OK. Note: this is just the default value; the actual switch will happen in code dynamically.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img height="283" src="http://cs.infopathdev.com/photos/blog_pictures/images/321/original.aspx" style="width:409px;height:283px;" width="409" /&gt;&lt;/p&gt;&lt;p&gt;Here is what the form looks like with some layout and formatting:&lt;/p&gt;&lt;p&gt;&lt;img height="189" src="http://cs.infopathdev.com/photos/blog_pictures/images/322/original.aspx" style="width:547px;height:189px;" width="547" /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Create the function to obtain the data source items:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ol start="1" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Choose Programming | Microsoft Script Editor from the Tools menu (or press &lt;strong&gt;Alt+Shift+F11&lt;/strong&gt;).&lt;/li&gt;&lt;li&gt;Add the following function to your code:&lt;/li&gt;&lt;/ol&gt;&lt;p style="padding-left:40px;"&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td align="left" style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;function findDataCollection()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var selectedDataSource = XDocument.DOM.selectSingleNode(&amp;quot;/ns1:Sample/SelectedDataSource&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return XDocument.DOM.selectNodes(&amp;quot;/ns1:Sample/Set&amp;quot;+selectedDataSource.text+&amp;quot;/Set&amp;quot;+selectedDataSource.text+&amp;quot;Item&amp;quot;);&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;ol start="3" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Save, and then close the Microsoft Script Editor.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This function returns a set of items which we will&amp;nbsp;use to fill the drop-down entries.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Modify the&amp;nbsp;XSL file:&lt;/strong&gt;&lt;/p&gt;&lt;ol start="1" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Choose Extract Form Files from the File menu.&lt;/li&gt;&lt;li&gt;Close InfoPath.&lt;/li&gt;&lt;li&gt;Using a text editor, open View1.xsl.&lt;/li&gt;&lt;li&gt;Find:&lt;/li&gt;&lt;/ol&gt;&lt;p style="padding-left:40px;"&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td align="left" style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;lt;xsl:if test=&amp;quot;not(Set1/Set1Item[.=$val] or $val=&amp;#39;&amp;#39;)&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;option selected=&amp;quot;selected&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;value&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;$val&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;$val&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/xsl:if&amp;gt;&lt;br /&gt;&amp;lt;xsl:for-each select=&amp;quot;Set1/Set1Item&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;option&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;value&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:if test=&amp;quot;$val=.&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;selected&amp;quot;&amp;gt;selected&amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:if&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/xsl:for-each&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;ol start="5" style="margin-top:0px;margin-bottom:0px;"&gt;&lt;li&gt;Replace with:&lt;/li&gt;&lt;/ol&gt;&lt;p style="padding-left:40px;"&gt;&lt;table class="msoUcTable" style="table-layout:fixed;width:100%;border-collapse:collapse;word-wrap:break-word;border:medium none;"&gt;&lt;tr&gt;&lt;td align="left" style="background-color:#e6e6e6;border:#e6e6e6 6pt solid;"&gt;&lt;p&gt;&lt;font color="#333399" face="Courier New" style="font-size:10pt;"&gt;&amp;lt;xsl:if test=&amp;quot;$val=&amp;#39;&amp;#39;&amp;quot;&amp;gt; &amp;lt;!-- just to make the code more uniform --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;option selected=&amp;quot;selected&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;value&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;$val&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;$val&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/xsl:if&amp;gt;&lt;br /&gt;&amp;lt;xsl:for-each select=&amp;quot;xdExtension:findDataCollection()&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;option&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;value&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:if test=&amp;quot;$val=.&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:attribute name=&amp;quot;selected&amp;quot;&amp;gt;selected&amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:if&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:value-of select=&amp;quot;.&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/xsl:for-each&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;At this point the drop-down uses the &lt;font face="Courier New"&gt;findDataCollection()&lt;/font&gt; function to determine the data source of its entries. This causes the list of items to be dependant on the value selected&amp;nbsp;in &lt;font face="Courier New"&gt;SelectedDataSource&lt;/font&gt;. With this solution, if we select a value and then switch the data source, then the old value remains selected. If we want to clear &lt;font face="Courier New"&gt;TextField&lt;/font&gt;, we can easily use a rule or the &lt;font face="Courier New"&gt;onAfterChange&lt;/font&gt; event on the &lt;font face="Courier New"&gt;SelectedDataSource&lt;/font&gt; field.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;After these simple steps, the values that can be selected for &lt;font face="Courier New"&gt;TextField&lt;/font&gt; depends on the value of the &lt;font face="Courier New"&gt;SelectedDataSource&lt;/font&gt; field. The procedure is almost the same as if you wanted to dynamically bind a field to a control (e.g. Drop-Down List Box, Expression Box, Text Box, etc.). However, there is a side effect: after the change is done in the XSL, it is no longer possible to use the InfoPath designer to modify the dynamically bound-control. With this in mind, it is better to set everything you need (data validation, rules, conditional formatting, etc.) before you manually edit the&amp;nbsp;XSL file.&lt;/p&gt;&lt;img src="https://www.infopathdev.com:443/aggbug.aspx?PostID=323" width="1" height="1"&gt;</content><author><name>Anonymous</name><uri>https://www.infopathdev.com:443/members/Anonymous.aspx</uri></author></entry></feed>