From 196141bf72e092c911906d9530fa4ddf53bc3276 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 25 Jan 2006 04:56:19 +0000 Subject: Added TDropDownList validation demos. --- .../quickstart/protected/pages/Controls/List.page | 2 +- .../pages/Controls/Samples/TDropDownList/Home.page | 100 ++++++++++++++++++++- .../pages/Controls/Samples/TDropDownList/Home.php | 65 +++++++++++--- 3 files changed, 152 insertions(+), 15 deletions(-) (limited to 'demos') diff --git a/demos/quickstart/protected/pages/Controls/List.page b/demos/quickstart/protected/pages/Controls/List.page index 557a8c6f..d076da2f 100644 --- a/demos/quickstart/protected/pages/Controls/List.page +++ b/demos/quickstart/protected/pages/Controls/List.page @@ -27,7 +27,7 @@ Since TListControl inherits from TDataBoundControl, these list

TListBox

-TListBox displays a list box that allows single or multiple selection. Set the property SelectionMode as Single to make a single selection list box, and Multiple a multiple selection list box. The items in the list box are represented by the Items property. The number of rows displayed in the box is specified via the Rows property value. +TListBox displays a list box that allows single or multiple selection. Set the property SelectionMode as Single to make a single selection list box, and Multiple a multiple selection list box. The number of rows displayed in the box is specified via the Rows property value.

diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page index 5123cc94..ed3c07a3 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page @@ -77,7 +77,7 @@ Auto postback dropdown list: Dropdown list's behavior upon postback: - + @@ -90,4 +90,102 @@ Dropdown list's behavior upon postback: + +

DropDown Lists with DataBinding

+Use Ctrl + Mouse Click to change selection +
+ + + + + + + + + + + + + + + + + + +
+Databind to an integer-indexed array: + + + +
+Databind to an associative array: + + + +
+Databind with DataTextField and DataValueField specified: + + + +
+ + +

List Boxes with Validation

+ + + + + + + + + + + + + +
+Dropdown list is being validated: + + + + + + + + + +
+Dropdown list causing validation: + + + + + + + +
+ \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php index 5dfa3bba..c220d697 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php @@ -2,28 +2,67 @@ class Home extends TPage { - public function selectionChanged($sender,$param) + public function onLoad($param) { - if(($index=$sender->SelectedIndex)>=0) + parent::onLoad($param); + if(!$this->IsPostBack) { - $value=$sender->SelectedValue; - $text=$sender->SelectedItem->Text; - $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text)."; + $data=array('item 1','item 2','item 3','item 4'); + $this->DBDropDownList1->DataSource=$data; + $this->DBDropDownList1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBDropDownList2->DataSource=$data; + $this->DBDropDownList2->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->DBDropDownList3->DataSource=$data; + $this->DBDropDownList3->dataBind(); } - else - $this->SelectionResult->Text="Your selection is empty."; } - public function buttonClicked($sender,$param) + protected function collectSelectionResult($input,$output) { - if(($index=$this->ListBox1->SelectedIndex)>=0) + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) { - $value=$this->ListBox1->SelectedValue; - $text=$this->ListBox1->SelectedItem->Text; - $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text)."; + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n"; } + if($result==='') + $output->Text='Your selection is empty.'; else - $this->SelectionResult2->Text="Your selection is empty."; + $output->Text='Your selection is: '.$result; + } + + public function DBDropDownList1Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList1Result); + } + + public function DBDropDownList2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList2Result); + } + + public function DBDropDownList3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList3Result); + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->DropDownList1,$this->SelectionResult2); } } -- cgit v1.2.3