How to populate a dropdown with a WS in C#

T

T.Coita

Hi,


I have make a webservice I can make a call with the managed code C#
and I have a return !
no more probleme with that! I'm happy

But now I have my result in a XMLDocumenthow I can populate my dropdown
listebox in my infopath form?


Thanks for your help
It's very appreciated

Thierry
 
S

Scott L. Heim [MSFT]

Hi Thierry,

You can simply setup your web service as a "Data Source" and then use this
data source to populate your drop-down list:

- Right-click on the drop-down and choose Properties
- On the Data tab, look in the List Box Entries section and change the
option to: "Lookup values in a data connection to a database, web
service..."

I hope this helps!

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

T.Coita

Hi,

Thanks a lot for your answer!

I know that thanks! but What I need to do is in function of one field
(not thelistebox a textlabel) I need to send to the information to
webservice for populate my dropdownlistebox. And with this way I can't
do that!

Sorry I'm french I don't understand very well what you say! So:

I create a new datasource! ok but how to link this with my webservice
what is the correct call for call the secondary datasource in C#

for primary it's:

thisXDocument.DOM.selectSingleNode("");

but for the secondary how to do?


Thanks in Advance

Thierry
 
S

Scott L. Heim [MSFT]

Hi Thierry,

My apologies but I too am unsure of what you are trying to accomplish. It
sounds like you need to be able to enter a value in a field and then pass
this to your web service as, say a parameter, so that you can populate a
drop-down list based on the results of sending that value to your web
service - is this correct? If so, here is a sample of the steps I am using:

1) Create the C# Web Service
- Add a SQL DataAdapter (named daOrders) and set this to use the Orders
table from the Northwind SQL database (specifically the OrderID and
CustomerID fields)
- Create a DataSet (named dsOrders) from daOrders
- Add the following web method:

[WebMethod]
public DataSet GetOrders(string CustID)
{
if(CustID != "")
{
this.daOrders.SelectCommand.CommandText = "SELECT OrderID, CustomerID
FROM Orders WHERE CustomerID = '" + CustID + "'";
}
this.daOrders.Fill(dsOrders);
return dsOrders;
}

2) Create the InfoPath form
- Create a new, blank form
- Add a text box and named it: txtCustomerID
- Add a drop-down list box and named it: ddlOrders
- Add a new Data Connection to the above web service but choose to *not*
automatically get the data when the form is opened
- Right-click on ddlOrders, choose Properties and set the following
options:
- Data Connection: GetOrders
- Entries: Orders (use the Select XPath button to drilldown and select
Orders) and then click the "Filter Data" button, click Add and then set the
following options:
- 1st drop-down: select CustomerID from the Secondary Data Source
- 2nd drop-down: select "is equal to"
- 3rd drop-down: choose Select a Field or Group, select the Main data
source and then select txtCustomerID

** NOTE: What this filter is saying is: display data where the customerID
in the secondary data source is equal to the CustomerID that is entered in
the txtCustomerID field on the main form

- Click OK until you are back to the drop-down list Properties window

- Value: OrderID
- Display Name: OrderID

- Right-click on txtCustomerID, choose Properties and click the Rule button
- Click Add and complete the following:

- Click Add Action
- Choose: Set a Fields Value
- Click the button next to "Field" and select ddlOrders from the Main
data source
- Leave the Value field blank
- Click OK twice

- Click the Add button again and complete the following:

- Click the Add Action
- Choose: Query using a Data Connection
- Select the GetOrders data connection
- Click OK 4 times to get back to your InfoPath form

** NOTE: The first rule is used to clear previous entries in the drop-down
- the second rule actually queries the web service passing it the customer
ID that you enter.

3) Test
- Preview the form
- Enter BERGS in the text box and tab to the drop-down list - result: you
should see a series of Orders
- Enter ALFKI in the text box and tab to the drop-down list - result: you
should now see a series of different Orders

I hope all this helps Thierry!

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

T.Coita

Thanks a lot Scott It's what I need!

Without C# it's good, too!

but If I need to concat some markup in the answer of my webservice is
it possible or I need to make that with my webservice and add a special
markup for that?

Thanks a lot one more time! I begin now to try your solution !

++

Thierry

P.S. Your are MSFT ? I have a question for you : Who I can't send the
bug or the suggestion to improve infopath? I have now a list of what
don't work and what can be improve! I have also examples (xsn) for make
infopath "crazy" ! Thanks
 
B

B King

Great Post .. I was needing the same functionality. However, When I do
just as you prescribed in the post. I only get a single entry in the
drop-down list. The web service is returning multiple. But only the
first entry in the dataset gets populated into the dropdown list box.
Any ideas ?
 
S

Scott L. Heim [MSFT]

Hi Thierry,

I am glad the information helped!

In regard to your last question, please accept my apologies but I am unsure
of what you are asking. Could you provide some additional details or an
example?

Thanks,
Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Scott L. Heim [MSFT]

Hi,

That does seem odd...how did you confirm the web service is returning
multiple records? Did you test the asmx page?

Also, do you have the drop-down list bound to the proper fields (nodes) as
I had described? I don't know that I have seen a situation where the result
of the web service is correct but the InfoPath control does not have all
the data.

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top