summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Controls/Samples/TDropDownList
diff options
context:
space:
mode:
Diffstat (limited to 'demos/quickstart/protected/pages/Controls/Samples/TDropDownList')
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page100
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php65
2 files changed, 151 insertions, 14 deletions
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:
</td>
<td class="sampleaction">
-<com:TDropDownList ID="ListBox1">
+<com:TDropDownList ID="DropDownList1">
<com:TListItem Value="value 1" Text="item 1" />
<com:TListItem Value="value 2" Text="item 2" Selected="true" />
<com:TListItem Value="value 3" Text="item 3" />
@@ -90,4 +90,102 @@ Dropdown list's behavior upon postback:
</table>
+
+<h2>DropDown Lists with DataBinding</h2>
+<i>Use Ctrl + Mouse Click to change selection</i>
+<br/>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Databind to an integer-indexed array:
+</td>
+<td class="sampleaction">
+<com:TDropDownList ID="DBDropDownList1"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBDropDownList1Changed" />
+<com:TLabel ID="DBDropDownList1Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind to an associative array:
+</td>
+<td class="sampleaction">
+<com:TDropDownList ID="DBDropDownList2"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBDropDownList2Changed" />
+<com:TLabel ID="DBDropDownList2Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind with DataTextField and DataValueField specified:
+</td>
+<td class="sampleaction">
+<com:TDropDownList ID="DBDropDownList3"
+ AutoPostBack="true"
+ DataTextField="name"
+ DataValueField="id"
+ OnSelectedIndexChanged="DBDropDownList3Changed" />
+<com:TLabel ID="DBDropDownList3Result" ForeColor="red" />
+</td>
+</tr>
+
+</table>
+
+
+<h2>List Boxes with Validation</h2>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Dropdown list is being validated:
+</td>
+<td class="sampleaction">
+<com:TDropDownList ID="VDropDownList1">
+ <com:TListItem Value="value 1" Text="item 1" />
+ <com:TListItem Value="value 2" Text="item 2" />
+ <com:TListItem Value="value 3" Text="item 3" />
+ <com:TListItem Value="value 4" Text="item 4" />
+</com:TDropDownList>
+<com:TRequiredFieldValidator
+ ControlToValidate="VDropDownList1"
+ ErrorMessage="You must make a selection other than the first option"
+ InitialValue="value 1"
+ Display="Dynamic"
+ ValidationGroup="Group1"
+ />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Dropdown list causing validation:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox" />
+<com:TRequiredFieldValidator
+ ControlToValidate="TextBox"
+ ErrorMessage="You must enter a value"
+ Display="Dynamic"
+ ValidationGroup="Group2"
+ />
+<com:TDropDownList
+ ID="VDropDownList2"
+ AutoPostBack="true"
+ ValidationGroup="Group2">
+ <com:TListItem Text="Agree" />
+ <com:TListItem Text="Disagree" />
+</com:TDropDownList>
+</td>
+</tr>
+
+</table>
+
</com:TContent> \ 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);
}
}