summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater
diff options
context:
space:
mode:
Diffstat (limited to 'demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater')
-rw-r--r--demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.page92
-rw-r--r--demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php79
2 files changed, 171 insertions, 0 deletions
diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.page b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.page
new file mode 100644
index 00000000..4d855cbc
--- /dev/null
+++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.page
@@ -0,0 +1,92 @@
+<com:TContent ID="body">
+
+<h1>TActiveRepeater Sample</h1>
+
+<p>
+The following example allows users to modify the existing tabular data using a <tt>TActiveRepeater</tt>. Two validators are used in the repeater to ensure the validity of user inputs. One is to ensure product names are not empty, the other ensures product prices are valid numeric format. After clicking on the <tt>save</tt> button, the input data is displayed in a table at the bottom of the page.
+</p>
+
+<table>
+<tr>
+ <th>Name</th>
+ <th>Category</th>
+ <th>Price</th>
+ <th>Imported</th>
+</tr>
+<com:TActiveRepeater ID="Repeater" OnItemDataBound="repeaterDataBound">
+<prop:ItemTemplate>
+<tr>
+ <td>
+ <com:TTextBox
+ ID="ProductName"
+ Text=<%#$this->Data['name']%> />
+ </td>
+ <td>
+ <com:TDropDownList
+ ID="ProductCategory" />
+ </td>
+ <td>
+ <com:TTextBox
+ ID="ProductPrice"
+ Columns="7"
+ Text=<%#$this->Data['price']%> />
+ </td>
+ <td>
+ <com:TCheckBox
+ ID="ProductImported"
+ Checked=<%#$this->Data['imported']%> />
+ <com:TRequiredFieldValidator
+ ControlToValidate="ProductName"
+ ErrorMessage="Product name cannot be empty."
+ Display="Dynamic" />
+ <com:TRegularExpressionValidator
+ ControlToValidate="ProductPrice"
+ RegularExpression="\d+(\.\d{1,2})?"
+ ErrorMessage="Product price must be in the format of ddd.dd"
+ Display="Dynamic" />
+ </td>
+</tr>
+</prop:ItemTemplate>
+</com:TActiveRepeater>
+</table>
+
+<div>
+<com:TActiveButton Text="Save" OnClick="saveInput"/>
+</div>
+
+<com:TSafeHtml>
+<com:TActiveRepeater ID="Repeater2" EnableViewState="false">
+
+<prop:HeaderTemplate>
+<table cellpadding="2">
+<tr style="color:white;background-color:black">
+ <th>ID</th>
+ <th>Name</th>
+ <th>Category</th>
+ <th>Price</th>
+ <th>Imported</th>
+</tr>
+</prop:HeaderTemplate>
+
+<prop:ItemTemplate>
+<tr style="<%# 'background-color:' . ($this->ItemIndex%2 ? '#BFCFFF' : '#E6ECFF') %>">
+<td><%#$this->Data['id']%></td>
+<td><%#$this->Data['name']%></td>
+<td><%#$this->Data['category']%></td>
+<td><%#$this->Data['price']%></td>
+<td><%#$this->Data['imported']?'Yes':'No'%></td>
+</tr>
+</prop:ItemTemplate>
+
+<prop:FooterTemplate>
+<tr style="color:white;background-color:black;text-align:center;">
+<td colspan="5">Computer Parts Inventory</td>
+</tr>
+</table>
+</prop:FooterTemplate>
+
+</com:TActiveRepeater>
+
+</com:TSafeHtml>
+
+<div class="last-modified">$Id: Sample3.page 1688 2007-02-09 22:48:31Z xue $</div></com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php
new file mode 100644
index 00000000..f7c8d61c
--- /dev/null
+++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php
@@ -0,0 +1,79 @@
+<?php
+
+class Home extends TPage
+{
+ protected function getProducts()
+ {
+ return array(
+ array('id'=>'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true),
+ array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true),
+ array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true),
+ array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false),
+ array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true),
+ array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false),
+ array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false),
+ array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true),
+ array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true),
+ array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false),
+ );
+ }
+
+ protected function getCategories()
+ {
+ return array(
+ array('id'=>'CAT001','name'=>'Accessories'),
+ array('id'=>'CAT002','name'=>'Input Devices'),
+ array('id'=>'CAT003','name'=>'Drives'),
+ array('id'=>'CAT004','name'=>'Barebone'),
+ );
+ }
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->Repeater->DataSource=$this->Products;
+ $this->Repeater->dataBind();
+ }
+ }
+
+ public function repeaterDataBound($sender,$param)
+ {
+ $item=$param->Item;
+ if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ {
+ $item->ProductCategory->DataSource=$this->Categories;
+ $item->ProductCategory->DataTextField='name';
+ $item->ProductCategory->DataValueField='id';
+ $item->ProductCategory->dataBind();
+ $item->ProductCategory->SelectedValue=$item->DataItem['category'];
+ }
+ }
+
+ public function saveInput($sender,$param)
+ {
+ if($this->IsValid)
+ {
+ $index=0;
+ $products=$this->Products;
+ $data=array();
+ foreach($this->Repeater->Items as $item)
+ {
+ $item=array(
+ 'id'=>$products[$index]['id'],
+ 'name'=>$item->ProductName->Text,
+ 'category'=>$item->ProductCategory->SelectedItem->Text,
+ 'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text),
+ 'imported'=>$item->ProductImported->Checked,
+ );
+ $data[]=$item;
+ $index++;
+ }
+ $this->Repeater2->DataSource=$data;
+ $this->Repeater2->dataBind();
+ }
+ }
+}
+
+?> \ No newline at end of file