From 598fac7617264c20b5c7e6f914b5aba18a677b01 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 19 Jan 2006 17:14:45 +0000 Subject: Fix a few issues with listcontrols about databinding. --- .../pages/Controls/Samples/TListBox/Home.page | 52 +++++++++++++- .../pages/Controls/Samples/TListBox/Home.php | 79 +++++++++++++++------- 2 files changed, 104 insertions(+), 27 deletions(-) (limited to 'demos/quickstart/protected') diff --git a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page index f6640879..66ac4fa2 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page @@ -142,7 +142,9 @@ List box's behavior upon postback: Auto postback list box: - + @@ -154,4 +156,52 @@ Auto postback list box: +

List Boxes with DataBinding

+Use Shift + Mouse Click to change selection +
+ + + + + + + + + + + + + + + + + + +
+Databind to an integer-indexed array: + + + +
+Databind to an associative array: + + + +
+Databind with DataTextField and DataValueField specified: + + + +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php index 6b1d07e1..cd9d7c13 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php @@ -2,50 +2,77 @@ class Home extends TPage { - public function selectionChanged($sender,$param) + public function onLoad($param) { - $index=$sender->SelectedIndex; - $value=$sender->SelectedValue; - $text=$sender->SelectedItem->Text; - $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text)."; + parent::onLoad($param); + if(!$this->IsPostBack) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->DBListBox1->DataSource=$data; + $this->DBListBox1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBListBox2->DataSource=$data; + $this->DBListBox2->dataBind(); + + $data=array( + array('id'=>'001','name'=>'John','age'=>31), + array('id'=>'002','name'=>'Mary','age'=>30), + array('id'=>'003','name'=>'Cary','age'=>20)); + $this->DBListBox3->DataSource=$data; + $this->DBListBox3->dataBind(); + } } - public function buttonClicked($sender,$param) + public function DBListBox1Changed($sender,$param) { - $index=$this->ListBox1->SelectedIndex; - $value=$this->ListBox1->SelectedValue; - $text=$this->ListBox1->SelectedItem->Text; - $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text)."; + $this->collectSelectionResult($sender,$this->DBListBox1Result); } - public function multiSelectionChanged($sender,$param) + public function DBListBox2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBListBox2Result); + } + + public function DBListBox3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBListBox3Result); + } + + protected function collectSelectionResult($input,$output) { - $indices=$sender->SelectedIndices; + $indices=$input->SelectedIndices; $result=''; foreach($indices as $index) { - $item=$sender->Items[$index]; + $item=$input->Items[$index]; $result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n"; } if($result==='') - $this->MultiSelectionResult->Text='Your selection is empty.'; + $output->Text='Your selection is empty.'; else - $this->MultiSelectionResult->Text='Your selection is: '.$result; + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->ListBox1,$this->SelectionResult2); + } + + public function multiSelectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->MultiSelectionResult); } public function buttonClicked2($sender,$param) { - $indices=$this->ListBox2->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$this->ListBox2->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n"; - } - if($result==='') - $this->MultiSelectionResult2->Text='Your selection is empty.'; - else - $this->MultiSelectionResult2->Text='Your selection is: '.$result; + $this->collectSelectionResult($this->ListBox2,$this->MultiSelectionResult2); } } -- cgit v1.2.3