10 Replies Latest reply on Feb 24, 2010 10:44 PM by venkatsyss

    Regarding Check and ID

    venkatsyss Level 1

      hi,

       

      My question how i concatenate one or more ids in http service when checkbox are selected in the dataGrid.

       

      The following Code shows the datagrid and the database Query.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="absolute" creationComplete="userRequest.send()">
      <mx:HTTPService id="userRequest" method="POST" useProxy="false" url="check.php" result="Display(event)">
           <mx:request xmlns="">
               <memid>{uRequest.selectedItem.userid}</memid>
           </mx:request>
      </mx:HTTPService>

       

      <mx:Script>
           <![CDATA[
               import mx.events.ListEvent;
               import mx.rpc.events.ResultEvent;
               import mx.collections.ArrayCollection;
               import mx.controls.Alert;
               import mx.controls.DataGrid;
               [Bindable]private var arr:ArrayCollection;
               private function Display(event:ResultEvent):void{
                   arr=event.result.users.user;

              }
               private function handleSelect(value:Boolean):void
                   {
                       userRequest.lastResult.users.user.source.forEach(
                           function callback(item:*, index:int,
      array:Array):void
                           {
                               item.sel = value;
                           });
                       userRequest.lastResult.users.user.refresh();
                   }
                   private function Update():void{
                       userRequest.send();
                   }

          ]]>
      </mx:Script>


      <mx:DataGrid dataProvider="{arr}" id="uRequest" >
      <mx:columns>
      <mx:DataGridColumn>
           <mx:itemRenderer>
           <mx:Component>
               <mx:CheckBox selected="{data.sel}">

              </mx:CheckBox>
           </mx:Component>
      </mx:itemRenderer>

          </mx:DataGridColumn>

          <mx:DataGridColumn headerText="Sl.No" dataField="userid"></
      mx:DataGridColumn>
               <mx:DataGridColumn dataField="username">

              </mx:DataGridColumn>
               <mx:DataGridColumn dataField="useremail">

              </mx:DataGridColumn>
               <mx:DataGridColumn dataField="userstate">

              </mx:DataGridColumn>

          </mx:columns>

      </mx:DataGrid>


      <mx:Button label="CheckAll" click="handleSelect(true)">

      </mx:Button>

       

      <mx:Button label="Update" click="Update()">

      </mx:Button>


      </mx:Application>

       

      //My Database Query

       

      if($_POST['memid']!=''){

              $id=implode(',',$_POST['memid']);

              $ids=substr($id,0,20);

              $ans="update tbl_member set member_lname='example' where member_id
      in($ids)";
               $res=mysql_query($ans);

              $answer="select * from tbl_member";
               $result=mysql_query($answer);

              print "<users>";

              while($row=mysql_fetch_object($result)){

              print "<user>
               <userid>".$row->member_id."</userid>
               <username>".$row->member_fname."</username>
               <useremail>".$row->member_lname."</useremail>
               <userstate>".$row->member_state."</userstate>
               </user>";

      }

              print"</users>";

       

      }

      Please provide me the solution to solve the problem.

       

      Thanks and Regards,

      venkat.R

        • 1. Re: Regarding Check and ID
          archemedia Level 4

          You could do something like:

           

          private function doIt():void

          {

               var a:Array = new Array();

               for each (var item:Object in myDataProvider)

               {

                    if (item.sel)

                    {

                         a.push(item.id);

                    }

               }

           

               var s:String = a.toString();

               //now, send s to your service

          }

           

          Does this help?

           

          Dany

          • 2. Re: Regarding Check and ID
            venkatsyss Level 1

            hi,

             

            Thanks for your reply.But i could not able to get the answer.

             

            The Error shows "Access of undefined property mydataProvider".

             

            If i have  used  dataprovider id "urequest" the answer will not display it.

             

            Please provide me the solution to solve the problem.

             

            Thanks and Regards,

            venkat.R

            • 3. Re: Regarding Check and ID
              archemedia Level 4

              private function doIt():void

              {

                   var a:Array = new Array();

                   for each (var item:Object in myDataProvider)

                   {

                        if (item.sel)

                        {

                             a.push(item.id);

                        }

                   }

               

                   var s:String = a.toString();

                   //now, send s to your service

              }

               

              It's just an example. myDataProvider should be replaced with the name of your ArrayCollection. This collection holds all your object. Suppose your ArrayCollection holds object like this:

               

              var myDataProvider:ArrayCollection = new ArrayCollection([{id: 1, sel: true}, {id:2, sel: false}]);

               

              In your case, the property names id and sel might be diffrent!

               

              Dany

              • 4. Re: Regarding Check and ID
                venkatsyss Level 1

                hi,

                 

                Thanks for your kind reply.i get the result successfully but i could not able to send the value to the service.

                 

                The followind code shows the http service.

                 


                     for each (var item:Object in arr)
                     {
                          if (item.sel)
                          {
                              selArr.push(item.userid);
                          }
                     }
                                 var s:String = selArr.toString();
                                userRequest.send();
                                              
                            }

                 

                 

                But i could not able to get the request.Please find me the solutions to solve the problem.

                 

                Thanks and Regards,

                venkat.R

                • 5. Re: Regarding Check and ID
                  venkatsyss Level 1

                  hi,

                   

                  Successfully i send the vardiable to the service and update the database.

                   

                  Thanks a lot for you given a  support  to me.

                   

                  Once again thanks.

                   

                  Thanks and Regards,

                  venkat.R

                  • 6. Re: Regarding Check and ID
                    archemedia Level 4

                    Great! Good luck

                     

                    d

                    • 7. Re: Regarding Check and ID
                      venkatsyss Level 1

                      hi,

                       

                      I have another question regarding checkbox.

                       

                      how i have to check, in  foreach or for loop  if i have selected manually in the  checkbox in itemrender in the datagrid.

                       

                       

                      Please provide me the solution to solve the problem.

                       

                      Thanks and Regards,

                      venkat.R

                      • 8. Re: Regarding Check and ID
                        venkatsyss Level 1

                        hi,

                         

                        Thanks for your  kind reply and  support for me.....

                         

                         

                        I have another question regarding checkbox.

                         

                         

                        how i have to check, in  foreach or for loop  if i have selected manually in the  checkbox in itemrender in the datagrid.

                         

                         

                        Please provide me the solution to solve the problem.

                         

                        Thanks and Regards,

                        venkat.R

                        • 9. Re: Regarding Check and ID
                          archemedia Level 4

                          Maybe this post will put you on your path. If not, just post a new topic.

                           

                          http://forums.adobe.com/thread/583996?tstart=0

                           

                          Dany

                           

                          Message was edited by: archemedia: corrected the link to the post

                          • 10. Re: Regarding Check and ID
                            venkatsyss Level 1

                            hi,

                             

                            Thanks for your kind reply.

                             

                            I have posted a new topic in the forum.

                             

                            The above path is shows the url:

                             

                            http://forums.adobe.com/thread/584714

                             

                            Please provide me the solution to solve the problem.

                             

                             

                            Thanks and Regards,

                            venkat.R