Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

DataGrid Refresh

Avatar

Former Community Member
Hey there.



I'm trying to get a Datagrid to refresh itself after I call a
function to change the data set I'm getting from a .ASP page doing
SQL queries. The problem is, even though I'm recalling the
<HTTPService> and getting new data, the Datagrid does not
refresh to reflect the new data. Any ideas?



Here's the code I've got for this component.




quote:





<?xml version="1.0" encoding="utf-8"?>

<mx:Canvas xmlns:mx="
http://www.adobe.com/2006/mxml"
width="1030" height="874" creationComplete="userRequest.send()"
borderStyle="none" cornerRadius="10">

<mx:Script>

<![CDATA[

private function send_data():void

{

userRequest.send();

}



public var Airport:Boolean = false;

public var Downtown:Boolean = false;

public var Midtown:Boolean = false;

public var Southwest:Boolean = false;

public var West:Boolean = false;

public var Toggle:String = "";



private function Toggles(Toggle:String):void

{

if(Toggle == "Airport")

{

if (Airport == false)

{

Airport = true;

Test.text = "true";

}



else

{

Airport = false;

Test.text = "false";

}

}

if(Toggle == "Downtown")

{

if (Downtown == false)

{

Downtown = true;

Test.text = "true";

}



else

{

Downtown = false;

Test.text = "false";

}



}







//restDG.selectedIndex="0"

}

]]>

</mx:Script>





<mx:HTTPService id="userRequest" url="DATAURL.ASP"
useProxy="false" method="POST">

<mx:request xmlns="">

<airport>

{Airport}

</airport>

<downtown>

{Downtown}

</downtown>

</mx:request>



</mx:HTTPService>

<mx:VDividedBox x="10" y="10" height="100%"
width="400">

<mx:Panel width="100%" height="100%"
layout="absolute">

<mx:TabNavigator x="0" y="0" width="380" height="386">

<mx:Canvas label="Location" width="369" height="357"
borderStyle="solid">

<mx:CheckBox x="10" y="10" label=" Airport"
fontFamily="Verdana" fontWeight="bold" fontSize="20"
change="{Toggles('Airport');send_data();}"/>

<mx:CheckBox x="10" y="86" label=" Downtown"
fontFamily="Verdana" fontWeight="bold" fontSize="20"
change="{Toggles('Downtown');send_data();}"/>

<mx:CheckBox x="10" y="154" label=" Midtown"
fontFamily="Verdana" fontWeight="bold" fontSize="20"/>

<mx:CheckBox x="10" y="226" label=" Southwest"
fontFamily="Verdana" fontWeight="bold" fontSize="20"/>

<mx:CheckBox x="10" y="294" label=" West"
fontFamily="Verdana" fontWeight="bold" fontSize="20"/>

<mx:Label x="218" y="124" id="Test"/>

</mx:Canvas>

<mx:Canvas label="Cuisine" width="370" height="100%">

</mx:Canvas>

<mx:Canvas label="Service &amp; Amenities"
width="369" height="100%">

</mx:Canvas>

</mx:TabNavigator>

</mx:Panel>



<mx:DataGrid x="10" y="439" width="400" height="100%"
dataProvider="{userRequest.lastResult.enter.reg}" fontSize="14"
id="restDG" selectedIndex="0">

<mx:columns>

<mx:DataGridColumn headerText="Resturant Name"
dataField="name" />

</mx:columns>

</mx:DataGrid>



</mx:VDividedBox>

<mx:Label x="522" y="6" text="{restDG.selectedItem.name}"
fontSize="26" fontFamily="Verdana" color="#000000"/>

<mx:Image x="418" y="10"
source="{restDG.selectedItem.photo}"/>

<mx:Label x="522" y="43"
text="{restDG.selectedItem.address}" fontSize="15"
fontFamily="Verdana" fontWeight="bold" color="#000000"/>

<mx:Label x="522" y="66"
text="{restDG.selectedItem.city},{restDG.selectedItem.state}
{restDG.selectedItem.zip}" fontSize="15" fontFamily="Verdana"
fontWeight="bold" color="#000000"/>

<mx:Label x="522" y="89"
text="{restDG.selectedItem.phonetxt}" fontWeight="bold"
fontSize="15" fontFamily="Verdana" fontStyle="italic"
color="#ff0000"/>

<mx:Label x="591" y="89"
text="{restDG.selectedItem.area_code}-{restDG.selectedItem.phone}"
fontSize="15" fontFamily="Verdana" fontWeight="bold"
color="#000000"/>

<mx:Label x="522" y="112"
text="{restDG.selectedItem.rangetxt}" fontFamily="Verdana"
fontSize="15" fontWeight="bold" fontStyle="italic"
color="#ff0000"/>

<mx:Label x="638" y="112"
text="{restDG.selectedItem.range}" fontFamily="Verdana"
fontSize="15" fontWeight="bold" color="#000000"/>

<mx:Label x="522" y="135"
text="{restDG.selectedItem.avgtxt}" fontFamily="Verdana"
fontSize="15" fontWeight="bold" color="#ff0000"
fontStyle="italic"/>

<mx:Label x="666" y="135"
text="{restDG.selectedItem.avg_ticket}" fontSize="15"
fontFamily="Verdana" fontWeight="bold"/>

<mx:Label x="522" y="158"
text="{restDG.selectedItem.seattxt}" fontFamily="Verdana"
fontSize="15" color="#ff0000" fontWeight="bold"
fontStyle="italic"/>

<mx:Label x="679" y="158"
text="{restDG.selectedItem.seating_capacity}" fontFamily="Verdana"
fontSize="15" fontWeight="bold"/>



</mx:Canvas>





8 Replies

Avatar

Level 3
Hi



Did you try makeObjectsBindable=true?



William Chan

Avatar

Level 3
<mx:HTTPService id="userRequest" url="DATAURL.ASP"
useProxy="false" method="POST" makeObjectsBindable=true >

Avatar

Former Community Member
I did some reading on this, and the makeObjectsBindable is on
by default, so this didn't help :(

Avatar

Former Community Member
You might be getting a fault back instead of a result?



Instead of relying on data binding with the
HTTPService.lastResult property,

register event handlers for the fault and result events on
your <mx:HTTPService>

tag and first, check whether you're getting a fault, and
then, in the result

handler simply update the dataProvider on your DataGrid
programmatically.



I'm assuming that you're SWF is hosted on the same server as
your ASP page?





Avatar

Former Community Member
I'm getting the first set of data just fine, so there's not a
connection fault. I even went and changed the Query to the second
query I was trying, and that data will come though also. It's just
when I resend the HTTPService to refresh the data and do a new
query. The data on the datagrid just won't refresh

Avatar

Former Community Member
Hi, I have the same issue here, even using events. Also the
datagrid only show the results when there is more than one result
on the xml answer .

Any ideas?



UPDATED: I found the solution. It is a IE cache problem. Add
expire header to the CGI answer and the datagrid will
update.

Avatar

Former Community Member
Instead of binding to lastResult, use a result handler and
check whether

you have an Array first or not... if not, wrap the result in
an Array. (Or

wrap in mx.collections.ArrayCollection if you want the data
to be bindable).