diff options
author | xue <> | 2006-02-01 18:09:18 +0000 |
---|---|---|
committer | xue <> | 2006-02-01 18:09:18 +0000 |
commit | a7edca99c188c574125785c87198606527981d01 (patch) | |
tree | 5a577ec59c497c306fbe661c3756dfdb5a201d53 /demos | |
parent | 5a7bac0a5c8342ce5812c16d1973e5affa188670 (diff) |
Added a new TDataList demo.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page | 116 | ||||
-rw-r--r-- | demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php | 88 |
2 files changed, 204 insertions, 0 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page new file mode 100644 index 00000000..018aabfd --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page @@ -0,0 +1,116 @@ +<com:TContent ID="body">
+
+<h1>TDataList Sample 2</h1>
+<p>This demo shows a simple application of TDataList control.</p>
+<p>TDataList allows you to show a list of data items (rows), edit, select and delete them.</p>
+
+<com:TDataList ID="DataList"
+ CellPadding="2"
+ CellSpacing="3"
+ GridLines="Both"
+ RepeatColumns="1"
+ RepeatLayout="Table"
+ RepeatDirection="Vertical"
+ OnEditCommand="editItem"
+ OnCancelCommand="cancelItem"
+ OnUpdateCommand="updateItem"
+ OnDeleteCommand="deleteItem"
+ OnSelectedIndexChanged="selectItem"
+ HeaderStyle.BackColor="#AAAADD"
+ ItemStyle.BackColor="#EEEEEE"
+ SeparatorStyle.BackColor="#FAFAFA"
+ FooterStyle.BackColor="#BBBBBB"
+ EditItemStyle.BackColor="lightgreen"
+ SelectedItemStyle.BackColor="lightyellow">
+<prop:HeaderTemplate>
+<div style="font-weight:bold; text-align:center;">Computer Parts</div>
+</prop:HeaderTemplate>
+
+<prop:ItemTemplate>
+<table border="0" width="100%">
+<tr><td>
+<com:TLinkButton
+ Text=<%#$this->Parent->DataItem['id']%>
+ CommandName="select"
+ />
+<%#$this->Parent->DataItem['name']%>
+</td>
+<td align="right">
+<com:TLinkButton
+ Text="Edit"
+ CommandName="edit"
+ />
+<com:TLinkButton
+ Text="Delete"
+ CommandName="delete"
+ Attributes.onclick="if(!confirm('Are you sure?')) return false;"
+ />
+</td></tr>
+</table>
+</prop:ItemTemplate>
+
+<prop:SelectedItemTemplate>
+<table border="1" width="100%">
+<tr><th>ID</th><th>Name</th><th>Quantity</th><th>Price</th></tr>
+<tr>
+<td align="right"><%#$this->Parent->DataItem['id'] %></td>
+<td align="right"><%#$this->Parent->DataItem['name'] %></td>
+<td align="right"><%#$this->Parent->DataItem['quantity'] %></td>
+<td align="right">$<%#$this->Parent->DataItem['price'] %></td>
+</tr>
+<tr><td colspan="4" align="right">
+<com:TLinkButton
+ Text="Edit"
+ CommandName="edit"
+ />
+<com:TLinkButton
+ Text="Delete"
+ CommandName="delete"
+ Attributes.onclick="if(!confirm('Are you sure?')) return false;"
+ />
+</td></tr>
+</table>
+</prop:SelectedItemTemplate>
+
+<prop:EditItemTemplate>
+<table border="0" width="100%">
+<tr>
+ <td align="right">ID</td>
+ <td><%#$this->Parent->DataItem['id']%></td>
+</tr>
+<tr>
+ <td align="right">Name</td>
+ <td><com:TTextBox
+ ID="ProductName"
+ Text=<%#$this->Parent->DataItem['name'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td align="right">Quantity</td>
+ <td><com:TTextBox
+ ID="ProductQuantity"
+ Text=<%#$this->Parent->DataItem['quantity'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td align="right">Price</td>
+ <td><com:TTextBox
+ ID="ProductPrice"
+ Text=<%#$this->Parent->DataItem['price'] %>
+ />
+ </td>
+</tr>
+<tr>
+ <td colspan="2" align="right">
+ <com:TLinkButton Text="Save" CommandName="update" />
+ <com:TLinkButton Text="Cancel" CommandName="cancel" />
+ </td>
+</tr>
+</table>
+</prop:EditItemTemplate>
+
+</com:TDataList>
+
+</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php new file mode 100644 index 00000000..ccc87498 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php @@ -0,0 +1,88 @@ +<?php
+
+class Sample2 extends TPage
+{
+ protected function getData()
+ {
+ // We use viewstate keep track of data.
+ // In real applications, data should come from database.
+ if(($data=$this->getViewState('Data',null))===null)
+ {
+ $data=array(
+ array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00),
+ array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00),
+ array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00),
+ array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00),
+ array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00),
+ array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00),
+ array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00),
+ );
+ $this->saveData($data);
+ }
+ return $data;
+ }
+
+ protected function saveData($data)
+ {
+ // In real applications, data should be saved to database.
+ $this->setViewState('Data',$data);
+ }
+
+ function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+ }
+
+ function editItem($sender,$param)
+ {
+ $this->DataList->EditItemIndex=$param->Item->ItemIndex;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ function cancelItem($sender,$param)
+ {
+ $this->DataList->SelectedItemIndex=-1;
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+
+ function updateItem($sender,$param)
+ {
+ $item=$param->Item;
+ $data=$this->Data;
+ $product=&$data[$item->ItemIndex];
+ $product['name']=$item->ProductName->Text;
+ $product['price']=TPropertyValue::ensureFloat($item->ProductPrice->Text);
+ $product['quantity']=TPropertyValue::ensureInteger($item->ProductQuantity->Text);
+ $this->saveData($data);
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$data;
+ $this->DataList->dataBind();
+ }
+
+ function deleteItem($sender,$param)
+ {
+ $data=$this->Data;
+ array_splice($data,$param->Item->ItemIndex,1);
+ $this->saveData($data);
+ $this->DataList->SelectedItemIndex=-1;
+ $this->DataList->EditItemIndex=-1;
+ $this->DataList->DataSource=$data;
+ $this->DataList->dataBind();
+ }
+
+ function selectItem($sender,$param)
+ {
+ $this->DataList->DataSource=$this->Data;
+ $this->DataList->dataBind();
+ }
+}
+
+?>
\ No newline at end of file |