3 Replies Latest reply on Jan 2, 2008 10:17 PM by Sreenivas R

    Problems binding a datagrid

    mac_55
      Hi, I'm returning the following XML from a webservice, and trying to bind it to a datagrid but nothing's happening...

      my datagrid code is as follows:

      <mx:DataGrid x="34" y="116" dataProvider="{TestApp.getChat.lastResult.getChatResult.NewDaSet.Table}" >
      <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="MessageText"/>
      <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
      <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
      </mx:columns>
      </mx:DataGrid>

      I'm aware that I've only set one of the datafields, but nothing is appearing in Column 1 :(
      XML is:

      <?xml version="1.0" encoding="utf-8"?>
      <NewDataSet>
      <Table>
      <TimeOfChat>2008-01-01T01:14:25.763+00:00</TimeOfChat>
      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>
      <Message>HELLO HELLO </Message>
      <Id>1</Id>
      </Table>

      <Table>
      <TimeOfChat>2008-01-01T01:14:29.437+00:00</TimeOfChat>
      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>
      <Message>HELLO HELLO </Message>
      <Id>2</Id>
      </Table>
      <Table>

      <TimeOfChat>2008-01-01T01:14:30.107+00:00</TimeOfChat>
      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>
      <Message>HELLO HELLO </Message>
      <Id>3</Id>
      </Table>
      <Table>
      <TimeOfChat>2008-01-01T01:14:30.513+00:00</TimeOfChat>

      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>
      <Message>HELLO HELLO </Message>
      <Id>4</Id>
      </Table>
      <Table>
      <TimeOfChat>2008-01-01T01:14:30.89+00:00</TimeOfChat>
      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>

      <Message>HELLO HELLO </Message>
      <Id>5</Id>
      </Table>
      <Table>
      <TimeOfChat>2008-01-01T01:14:31.187+00:00</TimeOfChat>
      <UserId>a7d6aa14-f359-4af5-827b-82577e143385</UserId>
      <Message>HELLO HELLO </Message>

      <Id>6</Id>
      </Table>
      </NewDataSet>


      Any suggestions?
        • 1. Re: Problems binding a datagrid
          callie16
          um, you set your data field to get "MessageText" but your XML says that your element is "Message"... have you just tried dataField="Message"?
          • 2. Re: Problems binding a datagrid
            mac_55 Level 1
            Yes, i noticed this afterwards, but still no luck...

            Using the result event of the WS i can see the xml in myResultEvent.result

            any other ideas?
            • 3. Re: Problems binding a datagrid
              Sreenivas R Adobe Employee
              I tried this code and it seems to work

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="white"
              creationComplete="TestApp.send()">

              <mx:Script>
              <![CDATA[
              import mx.rpc.events.ResultEvent;

              private function resultHandler(event:ResultEvent):void
              {
              xmldg.dataProvider = event.result.Table;
              }

              ]]>
              </mx:Script>

              <mx:HTTPService url="testData.xml" resultFormat="e4x" id="TestApp" result="resultHandler(event)"/>

              <mx:DataGrid x="95" y="116" id="xmldg" >
              <mx:columns>
              <mx:DataGridColumn headerText="Column 1" dataField="Message"/>
              <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
              <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
              </mx:columns>
              </mx:DataGrid>

              </mx:Application>

              Where testData.xml contains the same XML data.