summaryrefslogtreecommitdiff
path: root/demos/quickstart
diff options
context:
space:
mode:
Diffstat (limited to 'demos/quickstart')
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page52
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php79
2 files changed, 104 insertions, 27 deletions
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:
</td>
<td class="sampleaction">
-<com:TListBox AutoPostBack="true" SelectionMode="Multiple" SelectedIndexChanged="multiSelectionChanged">
+<com:TListBox AutoPostBack="true"
+ SelectionMode="Multiple"
+ SelectedIndexChanged="multiSelectionChanged">
<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" />
@@ -154,4 +156,52 @@ Auto postback list box:
</table>
+<h2>List Boxes with DataBinding</h2>
+<i>Use Shift + 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:TListBox ID="DBListBox1"
+ AutoPostBack="true"
+ SelectionMode="Multiple"
+ SelectedIndexChanged="DBListBox1Changed" />
+<com:TLabel ID="DBListBox1Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind to an associative array:
+</td>
+<td class="sampleaction">
+<com:TListBox ID="DBListBox2"
+ AutoPostBack="true"
+ SelectionMode="Multiple"
+ SelectedIndexChanged="DBListBox2Changed" />
+<com:TLabel ID="DBListBox2Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind with DataTextField and DataValueField specified:
+</td>
+<td class="sampleaction">
+<com:TListBox ID="DBListBox3"
+ AutoPostBack="true"
+ SelectionMode="Multiple"
+ DataTextField="name"
+ DataValueField="id"
+ SelectedIndexChanged="DBListBox3Changed" />
+<com:TLabel ID="DBListBox3Result" ForeColor="red" />
+</td>
+</tr>
+
+</table>
</com:TContent> \ 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);
}
}