[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TBoundColumn.php (source)

   1  <?php
   2  /**
   3   * TBoundColumn class file
   4   *
   5   * @author Qiang Xue <qiang.xue@gmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TBoundColumn.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * TDataGridColumn class file
  15   */
  16  Prado::using('System.Web.UI.WebControls.TDataGridColumn');
  17  
  18  /**
  19   * TBoundColumn class
  20   *
  21   * TBoundColumn represents a column that is bound to a field in a data source.
  22   * The cells in the column will be displayed using the data indexed by
  23   * {@link setDataField DataField}. You can customize the display by
  24   * setting {@link setDataFormatString DataFormatString}.
  25   *
  26   * If {@link setReadOnly ReadOnly} is false, TBoundColumn will display cells in edit mode
  27   * with textboxes. Otherwise, a static text is displayed.
  28   *
  29   * When a datagrid row is in edit mode, the textbox control in the TBoundColumn
  30   * can be accessed by one of the following two methods:
  31   * <code>
  32   * $datagridItem->BoundColumnID->TextBox
  33   * $datagridItem->BoundColumnID->Controls[0]
  34   * </code>
  35   * The second method is possible because the textbox control created within the
  36   * datagrid cell is the first child.
  37   *
  38   * @author Qiang Xue <qiang.xue@gmail.com>
  39   * @version $Id: TBoundColumn.php 1397 2006-09-07 07:55:53Z wei $
  40   * @package System.Web.UI.WebControls
  41   * @since 3.0
  42   */
  43  class TBoundColumn extends TDataGridColumn
  44  {
  45      /**
  46       * @return string the field name from the data source to bind to the column
  47       */
  48  	public function getDataField()
  49      {
  50          return $this->getViewState('DataField','');
  51      }
  52  
  53      /**
  54       * @param string the field name from the data source to bind to the column
  55       */
  56  	public function setDataField($value)
  57      {
  58          $this->setViewState('DataField',$value,'');
  59      }
  60  
  61      /**
  62       * @return string the formatting string used to control how the bound data will be displayed.
  63       */
  64  	public function getDataFormatString()
  65      {
  66          return $this->getViewState('DataFormatString','');
  67      }
  68  
  69      /**
  70       * @param string the formatting string used to control how the bound data will be displayed.
  71       */
  72  	public function setDataFormatString($value)
  73      {
  74          $this->setViewState('DataFormatString',$value,'');
  75      }
  76  
  77      /**
  78       * @return boolean whether the items in the column can be edited. Defaults to false.
  79       */
  80  	public function getReadOnly()
  81      {
  82          return $this->getViewState('ReadOnly',false);
  83      }
  84  
  85      /**
  86       * @param boolean whether the items in the column can be edited
  87       */
  88  	public function setReadOnly($value)
  89      {
  90          $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
  91      }
  92  
  93      /**
  94       * Initializes the specified cell to its initial values.
  95       * This method overrides the parent implementation.
  96       * It creates a textbox for item in edit mode and the column is not read-only.
  97       * Otherwise it displays a static text.
  98       * The caption of the button and the static text are retrieved
  99       * from the datasource.
 100       * @param TTableCell the cell to be initialized.
 101       * @param integer the index to the Columns property that the cell resides in.
 102       * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
 103       */
 104  	public function initializeCell($cell,$columnIndex,$itemType)
 105      {
 106          parent::initializeCell($cell,$columnIndex,$itemType);
 107          switch($itemType)
 108          {
 109              case TListItemType::EditItem:
 110                  $control=$cell;
 111                  if(!$this->getReadOnly())
 112                  {
 113                      $textBox=Prado::createComponent('System.Web.UI.WebControls.TTextBox');
 114                      $cell->getControls()->add($textBox);
 115                      $cell->registerObject('TextBox',$textBox);
 116                      $control=$textBox;
 117                  }
 118                  if(($dataField=$this->getDataField())!=='')
 119                      $control->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
 120                  break;
 121              case TListItemType::Item:
 122              case TListItemType::AlternatingItem:
 123              case TListItemType::SelectedItem:
 124                  if($this->getDataField()!=='')
 125                      $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
 126                  break;
 127          }
 128      }
 129  
 130      /**
 131       * Databinds a cell in the column.
 132       * This method is invoked when datagrid performs databinding.
 133       * It populates the content of the cell with the relevant data from data source.
 134       */
 135  	public function dataBindColumn($sender,$param)
 136      {
 137          $item=$sender->getNamingContainer();
 138          $data=$item->getDataItem();
 139          $formatString=$this->getDataFormatString();
 140          if(($field=$this->getDataField())!=='')
 141              $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
 142          else
 143              $value=$this->formatDataValue($formatString,$data);
 144          if(($sender instanceof TTableCell) || ($sender instanceof TTextBox))
 145              $sender->setText($value);
 146      }
 147  }
 148  
 149  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7