Getting row number into a partial view

I am manually displaying info from a CActiveDataProvider. I want to get the odd/even class rendered for the row in a renderPartial() call. Can anyone help?

in view file:




   $idx=0;

   $hdrProtocol;

   foreach($dp as $row) {

      if($row->Protocol != $hdrProtocol) {

         echoHeader($row);

         $hdrProtocol = $row->Protocol;           

      } //EndIf          

      ++$idx;

      $this->renderPartial('_publicIP',$row);

   } //Next $row  



in partial _view file:




<?php $class = ($idx%2)? 'odd' :'even'; ?> 

   <tr class="<?php echo $class ?>">

      <td><?php echo CHtml::encode($data->Purpose); ?></td>

      <td><?php echo CHtml::encode($data->Location); ?></td>

      <td><?php echo CHtml::encode($data->Address); ?></td>

      <td><?php echo CHtml::encode($data->Pswrd); ?></td>

   </tr>



replace




$this->renderPartial('_publicIP',$row);



for




$this->renderPartial('_publicIP',array('data'=>$row,'rowNumber'=>$idx));



very close was




$this->renderPartial('_publicIP',array('data'=>$row,'idx'=>$idx));



and you can actually

view:




   $class='';

   $idx=0;

   $hdrProtocol;

   foreach($dp as $row) {

      if($row->Protocol != $hdrProtocol) {

         echoHeader($row);

         $hdrProtocol = $row->Protocol;           

      } //EndIf          

      $class = (++$idx%2)? 'odd' :'even';

      $this->renderPartial('_publicIP',array('data'=>$row,'class'=>$class));

   } //Next $row  



partial:




<tr class="<?php echo $class ?>">

      <td><?php echo CHtml::encode($data->Purpose); ?></td>

      <td><?php echo CHtml::encode($data->Location); ?></td>

      <td><?php echo CHtml::encode($data->Address); ?></td>

      <td><?php echo CHtml::encode($data->Pswrd); ?></td>

   </tr>



Very cool. I knew it was something simple. I liked/used Antonio’s idea. Thank you all.