From a7edca99c188c574125785c87198606527981d01 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 1 Feb 2006 18:09:18 +0000 Subject: Added a new TDataList demo. --- .../pages/Controls/Samples/TDataList/Sample2.page | 116 +++++++++++++++++++++ .../pages/Controls/Samples/TDataList/Sample2.php | 88 ++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php (limited to 'demos/quickstart/protected/pages/Controls/Samples') 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 @@ + + +

TDataList Sample 2

+

This demo shows a simple application of TDataList control.

+

TDataList allows you to show a list of data items (rows), edit, select and delete them.

+ + + +
Computer Parts
+
+ + + + + +
+Parent->DataItem['id']%> + CommandName="select" + /> +<%#$this->Parent->DataItem['name']%> + + + +
+
+ + + + + + + + + + + +
IDNameQuantityPrice
<%#$this->Parent->DataItem['id'] %><%#$this->Parent->DataItem['name'] %><%#$this->Parent->DataItem['quantity'] %>$<%#$this->Parent->DataItem['price'] %>
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + +
ID<%#$this->Parent->DataItem['id']%>
NameParent->DataItem['name'] %> + /> +
QuantityParent->DataItem['quantity'] %> + /> +
PriceParent->DataItem['price'] %> + /> +
+ + +
+
+ +
+ +
\ 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 @@ +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 -- cgit v1.2.3