1 Reply Latest reply on Jan 16, 2011 8:57 AM by Gregory Lafrance

    deleting record from advancedatagrid

    flx23

      Hi all

       

      i have a advancedatagrid where i have displayed the data and further added a delete button i want to delete record on the click of this button such that i get the corresponding id for the record from the first column that is lblcityid ..based on which i should exceute the delete sql query and remove the same from DB

       

      my code:-

      <mx:AdvancedDataGrid se   id="dgCity" visible="true"  width="554" height="270">

                      <mx:columns>

       

                      <mx:AdvancedDataGridColumn id="lblCityId" visible="true" headerText="id" dataField="intCityId" width="130"/>

                      <mx:AdvancedDataGridColumn headerText="City" dataField="strCityName" width="130"/>

       

                     <mx:AdvancedDataGridColumn  width="140">

          <mx:itemRenderer>

      <mx:Component>

      <mx:HBox>

      <mx:Script>

      <![CDATA[

       

      private function DeleteCity(event:Event):void

      {

       

      }

      ]]>

      </mx:Script>

      <mx:LinkButton id="lnkDelete" label="delete" click="DeleteCity(event)"  rollOverColor="#fd9595"/>

       

      </mx:HBox>

      </mx:Component> 

          </mx:itemRenderer>

      </mx:AdvancedDataGridColumn>

      </mx:columns>

                      </mx:AdvancedDataGrid>

        • 1. Re: deleting record from advancedatagrid
          Gregory Lafrance Level 6

          The code below shows a cleaner way to do it, and it answers your question:

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">    
              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                  
                      [Bindable] public var myDP:ArrayCollection = new ArrayCollection([
                          {intCityId: 1, strCityName: "London"},
                          {intCityId: 2, strCityName: "Paris"},
                          {intCityId: 3, strCityName: "New York"},
                          {intCityId: 4, strCityName: "Istanbul"},
                          {intCityId: 5, strCityName: "Tokyo"},
                          {intCityId: 6, strCityName: "Moscow"}
                      ]);               
                  ]]>
              </mx:Script>
            <mx:AdvancedDataGrid id="dgCity" visible="true"  
              width="554" height="270" dataProvider="{myDP}">
              <mx:columns>
                <mx:AdvancedDataGridColumn id="lblCityId" visible="true" 
                  headerText="id" dataField="intCityId" width="130"/>
                <mx:AdvancedDataGridColumn headerText="City" dataField="strCityName" width="130"/>
                <mx:AdvancedDataGridColumn  width="140">
                  <mx:itemRenderer>
                    <mx:Component>
                      <mx:LinkButton label="delete" rollOverColor="#fd9595"
                        click="outerDocument.myDP.removeItemAt(outerDocument.dgCity.selectedIndex)"/>
                    </mx:Component>  
                  </mx:itemRenderer>
                </mx:AdvancedDataGridColumn>
              </mx:columns>
            </mx:AdvancedDataGrid>
          </mx:Application>
          


          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.stardustsystems.com
          Adobe Flex Development and Support Services

          1 person found this helpful