8 Replies Latest reply on Dec 4, 2008 7:18 AM by rtalton

    Binding Grid with Web Services

    Krish.praveen Level 1

      I am using web service to fill a grid, in the web method i have to pass two parameters, it will return result of xml document. The same i want to fill in a DataGrid using Flex.

      Please help me..its urgent
        • 1. Re: Binding Grid with Web Services
          gallaharsha Level 1
          This is very easy. Send a httpservice with the two parameters to the backend which gives back an xml document. You can use that as the dataprovider of the grid.
          In case you want further details post the sample xml code and i can post a detailed code as to how to do this . also mention the backend u r using..
          • 2. Re: Binding Grid with Web Services
            Krish.praveen Level 1
            Thank you for reply..but i want to use web service instead of http service.
            Sending you the sample code..please work on that and help me in binding to the grid.


            <?xml version="1.0" encoding="utf-8"?>
            <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" verticalAlign="middle" width="900" height="600" creationComplete="initApp()" backgroundGradientColors="[0x000000,0x323232]" viewSourceURL="srcview/index.html">

            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.controls.Label;
            import mx.controls.Button;
            import mx.controls.TextInput;
            import mx.controls.DataGrid;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ObjectUtil;

            private function initApp():void
            trace("Hello from Flex Debugging!");
            private function auth():void{
            private function Authenticate_result(evt1:ResultEvent):void{
            token.text = ObjectUtil.toString(evt1.result);

            private function Authenticate_fault(evt2:FaultEvent):void{
            token.text = ObjectUtil.toString(evt2.message);

            private function GetloggedInUserList_result(event:ResultEvent):void{
            token1.text= "Result";
            var adg:DataGrid = new DataGrid();
            dg.dataProvider= event.result.toString();
            //adg.dataProvider = XML(event.result).toString();

            private function GetloggedInUserList_fault(evt4:FaultEvent):void{
            token1.text= "Fault";



            <mx:WebService id="S"
            wsdl=" http://localhost:2630/Web%20Services/Authentication.asmx?WSDL" useProxy="false">
            <mx:operation name="Authenticate"
            <mx:request xmlns="">

            <mx:WebService id="S1"
            wsdl=" http://localhost:2630/Web%20Services/ResourceManager.asmx?WSDL" showBusyCursor="true" useProxy="false">
            <mx:operation name="GetloggedInUserList"
            <mx:request xmlns="">

            <mx:Label x="303" y="10" text="Login Procedure....." width="186" fontSize="15" fontWeight="bold" color="#DFEAE7"/>
            <mx:Button x="100" y="117" label="Login" id ="btnOk" click="auth();" width="60"/>
            <mx:Label x="100" y="172" id="token" color="#E3EEF1"/>
            <mx:Label x="100" y="198" id="token1" color="#F4F8F9"/>
            <mx:Label x="10" y="61" text="User Name:" id="_lblUsername" color="#F2EFEF"/>
            <mx:Label x="20" y="87" text="Password:" id="_lblPassword" color="#F2EFEF"/>
            <mx:TextInput x="100" y="61" id="_txtuserid" text="demo" width="142"/>
            <mx:TextInput x="100" y="87" id="_txtpassword" text="demo" width="142" displayAsPassword="true"/>
            <mx:Button x="194" y="117" label="Exit" id="btnExit" click="this.close();"/>
            <mx:DataGrid id="adg" width="100%" height="351" y="247" >


            After login..i want to fill the result in the datagrid

            Help me in doing the same
            thanks in advance
            • 3. Re: Binding Grid with Web Services
              Krish.praveen Level 1
              I am using SQL as backend. This is called by webservice
              • 4. Re: Binding Grid with Web Services
                rtalton Level 4
                Looks like you are using ASP.NET
                Dumb question: Does your web service method accept parameters?
                • 5. Re: Binding Grid with Web Services
                  Krish.praveen Level 1
                  Yes..i am using ASP.Net
                  Fine with the question, but its taking the parameters.

                  Only problem is to show result in the grid.
                  Please go to the code, which i worked on.

                  Thanks in advance
                  • 6. Re: Binding Grid with Web Services
                    rtalton Level 4
                    I understand.

                    1) In GetloggedInUserList_result, get rid of the var "adg:DataGrid = new DataGrid();". You already have the data grid declared in MXML so you don't need to do this.
                    2) Instead of "dg.dataProvider= event.result.toString();"... (btw your datagrid's id is "adg", NOT "dg")...
                    ... try adg.dataProvider= S1.GetloggedInUserList.lastResult;

                    I can't see the data you are returning, but this should get you started in the right direction.
                    Remember you can always examine the returned data and see how to assign it to the datagrid's dataprovider property.
                    • 7. Re: Binding Grid with Web Services
                      Krish.praveen Level 1
                      we are getting variable not found error. and our data returns from web service is in xml format. Is any process to convert xml to any format and then bind to datagrid?
                      • 8. Re: Binding Grid with Web Services
                        rtalton Level 4
                        Check your returned data to see how it is formatted. XML format is fine to use for a datagrid.