PDA

View Full Version : query in flex


bosewicht
04-30-2009, 08:25 PM
I am using some example flex code to populate datagrids but there seems to be a problem somewhere. My asmx page is working fine, but the flex code below doesn't seem to get the xml data. Can anyone help?


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" layout="absolute">
<mx:Script>
<![CDATA[
//Run once Flex has loaded
private function init():void
{
//Send Get Request to .NET Web Service
yourWebServiceID.getDataXML.send();

}

]]>
</mx:Script>
<mx:WebService id="yourWebServiceID" wsdl="http://myWebService/Summary.asmx" showBusyCursor="true">
<mx:operation name="getDataXML" resultFormat="e4x">
<mx:request>
<strQuery>
SELECT * FROM MyTable ORDER BY myField
</strQuery>
<strRootNode>root</strRootNode>
<strItemNode>item</strItemNode>
</mx:request>
</mx:operation>
</mx:WebService>

<mx:DataGrid width="100%" height="100%" dataProvider="{yourWebServiceID.getDataXML.lastResult.root.item}"/>
</mx:Application>

ok, so debugging i get

warning: unable to bind to property ‘root’ on class ‘XMLList’ (class is not an IEventDispatcher)
warning: unable to bind to property ‘item’ on class ‘XMLList’ (class is not an IEventDispatcher)

autokad
05-01-2009, 04:38 PM
I did it differntly, see if this helps


import mx.rpc.events.ResultEvent;
import mx.rpc.events.InvokeEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;

private function onFault(e: Event):void
{
Alert.show(e.toString());
}

]]>
</mx:Script>

<mx:Form x="22" y="10" width="493">
<mx:HBox>
<mx:Label text="Username"/>
<mx:TextInput id="username" text="karl"/>
</mx:HBox>
<mx:Button label="Submit" click="userRequest.send();"/>
</mx:Form>

<!--Note, my asp page sends back:
<users>
<user>
<userid></userid>
<username></username>
<emailaddress></emailaddress>
</user>
</users>
-->
<mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.user}">
<mx:columns>
<mx:DataGridColumn headerText="User ID" dataField="userid"/>
<mx:DataGridColumn headerText="User Name" dataField="username"/>
<mx:DataGridColumn headerText="emailaddress" dataField="emailaddress"/>
</mx:columns>
</mx:DataGrid>

<mx:HTTPService id="userRequest" url="http://bobolink/test2.asp" resultFormat="e4x"
fault="onFault(event);" useProxy="false" method="POST">
<mx:request xmlns="">
<username>{username.text}</username>
</mx:request>
</mx:HTTPService>