Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

Filling a ComboBox from a webservice

Hi, I figured out how to populate DataGrids in Flex 3, from a .Net asmx web service.  My service returns a DataTable, and this procedure is straightforward and works fine:

http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_6.html

But I can't seem to figure out how to apply the same idea to ComboBox.  How do you populate a ComboBox from a webservice (preferably one that returns a DataTable but any format is fine)?

0
dparkes
Asked:
dparkes
1 Solution
 
hockeyragazzoCommented:
I'm not entirely sure if this will help you, but DataGrids and ComboBoxes use different dataProvider types. A DataGrid uses an ArrayCollection while a ComboBox uses an Array. When I populate an array, I use a simple for loop to iterate through the data I receive from my server. Attached is the code for how I would do it...(presumably if you've been able to populate a DataGrid you know how to read the data that you have from the server)...
[Bindable] private var myArray:Array = new Array();
 
private function populateMyArray(event:ResultEvent):void {
	
	var dataObj:Object = JSON.decode(String(event.result));
	
	var numChil = dataObj.NumberOfItems;
	
	myArray = new Array();
 
	for (var i:int=0; i<numChil; i++) {
		myArray.push(dataObj.Items[i].FirstName;
	}
}
 
<mx:ComboBox dataProvider="{myArray}"/>

Open in new window

0
 
dparkesAuthor Commented:
Thanks for showing me that method.  I actually figured out how to do it with my ASP.Net DataTable using the same method that I had linked above.
 
It was a simple oversight on my part.  I had just needed add the 'name' tag to the ComboBox so that it matched to column name in the DataTable.
 
So in my case, the Flex code is something like this:

XML:

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="652" height="132" title="Large Format Black &amp; White Detail" creationComplete="initApp();">
<mx:WebService
id="nwCL"
wsdl="http://upload.mycompany.com/asmxwebservices/MyService.asmx?WSDL"
result="onResult(event)"
fault="onFault(event)" />
<mx:ComboBox x="117" y="20" width="183" id="dMediaSize" labelField="name" color="#000000"/>
</mx:TitleWindow>

Script:
 
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
 
public function initApp():void{ 
nwCL.GetMediaTable();}
 
private function onResult(event:ResultEvent):void { 
try 
{ 
if (event.result.Tables != null) 
{ 
if (event.result.Tables.MediaTable != null) 
{ 
dMediaSize.dataProvider = event.result.Tables.MediaTable.Rows; 
} 
} 
} 
catch(err:Error) {} 
finally {} 
}
 
 
private function onFault(event:FaultEvent):void {
    //Alert.show(event.fault.toString());
    Alert.show("Error reading data table.");
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now