[Original] implement a linkage drop-down list box in infopath Forms Services (3)

Source: Internet
Author: User

Implement a linked drop-down list box in the duplicate table

If you use the methods described in the previous two articles to implement a linked drop-down list box in the repeated tables, the problem may occur. That is, when you change the upper-level drop-down list box of a row in the duplicate table, the options of the lower-level drop-down list box of all rows will become the same content. This problem occurs because the lower-level drop-down lists of all rows in the duplicate table use the same auxiliary data source, and the secondary data source will be changed when any parent drop-down lists change. To solve this problem, you must set different data sources for each lower-level drop-down list box. I found an article on the infopathdev blog (see [3]) and found a solution.

The solution is to add a duplicate field to the duplicate table and use this field as the data source of the lower-level drop-down list box. When the upper-level drop-down list box in the same row changes, the program updates the duplicate domain. Since each row of the duplicate table has its own repeated fields, the data sources in the lower drop-down list boxes of each row are different and will not affect each other. The following describes the detailed implementation steps.

Step 1: Prepare the data source list.

In this example, you need an original data source and still use the Sharepoint list created in the previous article-cities. The value of the repeat field in the repeat table is a subset of the table, which is obtained based on the value of the drop-down list box at the upper level.

Step 2: design the infopath form.

1. Put a duplicate table on the form, and put two drop-down lists ddlb1 and ddlb2 In the duplicate table. Add a duplicate domain ddlb2source to the primary data source, as shown in.


2. Check that "DUPLICATE" is selected in the attribute box of the ddlb2source domain ".

3. In the drop-down list box of ddlb2, select "Search for values in the form data source" and select "/My: myfields/My: group1/My: group2/My: ddlb2source" as the item ".

4. Click the "browser form" page of The ddlb1 attribute in the drop-down list box to confirm that the sending-back setting is"Always".

5. Create a data connection and point to the Sharepoint list cities. For more information, see the previous article.

6. Confirm"Enable browser compatibility", Confirm that the security level is"Full Trust", See the previous article.

Step 3: vsta programming.

On the infopath form design page, right-click ddlb1 and selectProgramming/changed eventsTo enter the vsta programming environment. Insert the following code in the ddlb1_changed event.

Code
// Clear the selected ddlb2 values for the same row in the duplicate table
Xpathnavigator parent = E. Site. selectsinglenode ("..");
Parent. selectsinglenode ("My: ddlb2", namespacemanager). setvalue (string. Empty );

// Clear the value of the ddlb2source Field
Xpathnodeiterator items = parent. Select ("My: ddlb2source", namespacemanager );
While (items. Count! = 0)
{
Parent. selectsinglenode ("My: ddlb2source", namespacemanager). deleteself ();
Items = parent. Select ("My: ddlb2source", namespacemanager );
}

String matchingcitiesxpath = string. Format (
"/DFS: myfields/DFS: datafields/DFS: cities [@ province = '{0}']", E. newvalue );

// Obtain the set of nodes that meet the filtering conditions and add them to the ddlb2source domain one by one.
Foreach (xpathnavigator citynavigator in this. datasources ["Cities"]. createnavigator (). Select (
Matchingcitiesxpath, namespacemanager ))
{
Using (xmlwriter writer = parent. appendchild ())
{
Writer. writeelementstring ("ddlb2source", namespacemanager. lookupnamespace ("my "),
Citynavigator. getattribute ("city ",""));
}
}

The vsta programming interface after the code is added is shown in.

Step 4: publish the infopath form.

Method omitted. See the previous article.

Step 5: Apply the content type.

Method omitted. See the previous article.

Test the new form, as shown in figure.


Although this method can implement a linked drop-down list box in the repeated table, the performance is not very good. Because each row in the duplicate table stores a data source from the drop-down list box, if there are many rows in the duplicate table, the performance will inevitably be affected, which is the main disadvantage of this solution, there is no better solution. We look forward to the next version of infopath to solve this problem.

Download source code:Ddlbex3.rar

References

[3]. Implementing cascading dropdowns in forms server, David airapetyan, http://www.infopathdev.com/blogs/david/archive/2007/08/23/implementing-cascading-dropdowns-in-forms-server.aspx

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.