diff options
Diffstat (limited to 'demos')
4 files changed, 249 insertions, 24 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page index bc750cb8..00670343 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page @@ -133,4 +133,76 @@ Auto postback check box list: </table>
+
+
+<h2>Checkbox Lists with DataBinding</h2>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Databind to an integer-indexed array:
+</td>
+<td class="sampleaction">
+<com:TCheckBoxList ID="DBCheckBoxList1"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBCheckBoxList1Changed" />
+<com:TLabel ID="DBCheckBoxList1Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind to an associative array:
+</td>
+<td class="sampleaction">
+<com:TCheckBoxList ID="DBCheckBoxList2"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBCheckBoxList2Changed" />
+<com:TLabel ID="DBCheckBoxList2Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind with DataTextField and DataValueField specified:
+</td>
+<td class="sampleaction">
+<com:TCheckBoxList ID="DBCheckBoxList3"
+ AutoPostBack="true"
+ DataTextField="name"
+ DataValueField="id"
+ OnSelectedIndexChanged="DBCheckBoxList3Changed" />
+<com:TLabel ID="DBCheckBoxList3Result" ForeColor="red" />
+</td>
+</tr>
+
+</table>
+
+
+<h2>CheckBox List with Validation</h2>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+CheckBox 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:TCheckBoxList AutoPostBack="true" ValidationGroup="Group2">
+ <com:TListItem Text="Agree" />
+ <com:TListItem Text="Disagree" />
+</com:TCheckBoxList>
+</td>
+</tr>
+
+</table>
+
</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php index 3873ca30..08c6f3ca 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php @@ -2,35 +2,69 @@ class Home extends TPage
{
- public function buttonClicked($sender,$param)
+ public function onLoad($param)
{
- $indices=$this->CheckBoxList->SelectedIndices;
- $result='';
- foreach($indices as $index)
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
{
- $item=$this->CheckBoxList->Items[$index];
- $result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n";
+ $data=array('item 1','item 2','item 3','item 4');
+ $this->DBCheckBoxList1->DataSource=$data;
+ $this->DBCheckBoxList1->dataBind();
+
+ $data=array('key 1'=>'item 1','key 2'=>'item 2',
+ 'key 3'=>'item 3','key 4'=>'item 4');
+ $this->DBCheckBoxList2->DataSource=$data;
+ $this->DBCheckBoxList2->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->DBCheckBoxList3->DataSource=$data;
+ $this->DBCheckBoxList3->dataBind();
}
- if($result==='')
- $this->SelectionResult->Text='Your selection is empty.';
- else
- $this->SelectionResult->Text='Your selection is: '.$result;
}
- public function selectionChanged($sender,$param)
+ protected function collectSelectionResult($input,$output)
{
- $indices=$sender->SelectedIndices;
+ $indices=$input->SelectedIndices;
$result='';
foreach($indices as $index)
{
- $item=$sender->Items[$index];
- $result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n";
+ $item=$input->Items[$index];
+ $result.="(Index: $index, Value: $item->Value, Text: $item->Text)";
}
if($result==='')
- $this->SelectionResult2->Text='Your selection is empty.';
+ $output->Text='Your selection is empty.';
else
- $this->SelectionResult2->Text='Your selection is: '.$result;
+ $output->Text='Your selection is: '.$result;
+ }
+
+ public function buttonClicked($sender,$param)
+ {
+ $this->collectSelectionResult($this->CheckBoxList,$this->SelectionResult);
+ }
+
+ public function selectionChanged($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->SelectionResult2);
}
+
+ public function DBCheckBoxList1Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBCheckBoxList1Result);
+ }
+
+ public function DBCheckBoxList2Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBCheckBoxList2Result);
+ }
+
+ public function DBCheckBoxList3Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBCheckBoxList3Result);
+ }
+
}
?>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page index a65c4d2d..97fe260c 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page @@ -133,4 +133,76 @@ Auto postback radio button list: </table>
+
+
+<h2>Checkbox Lists with DataBinding</h2>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Databind to an integer-indexed array:
+</td>
+<td class="sampleaction">
+<com:TRadioButtonList ID="DBRadioButtonList1"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBRadioButtonList1Changed" />
+<com:TLabel ID="DBRadioButtonList1Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind to an associative array:
+</td>
+<td class="sampleaction">
+<com:TRadioButtonList ID="DBRadioButtonList2"
+ AutoPostBack="true"
+ OnSelectedIndexChanged="DBRadioButtonList2Changed" />
+<com:TLabel ID="DBRadioButtonList2Result" ForeColor="red" />
+</td>
+</tr>
+
+<tr>
+<td class="samplenote">
+Databind with DataTextField and DataValueField specified:
+</td>
+<td class="sampleaction">
+<com:TRadioButtonList ID="DBRadioButtonList3"
+ AutoPostBack="true"
+ DataTextField="name"
+ DataValueField="id"
+ OnSelectedIndexChanged="DBRadioButtonList3Changed" />
+<com:TLabel ID="DBRadioButtonList3Result" ForeColor="red" />
+</td>
+</tr>
+
+</table>
+
+
+<h2>RadioButton List with Validation</h2>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+RadioButton 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:TRadioButtonList AutoPostBack="true" ValidationGroup="Group2">
+ <com:TListItem Text="Agree" />
+ <com:TListItem Text="Disagree" />
+</com:TRadioButtonList>
+</td>
+</tr>
+
+</table>
+
</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php index 47d9b23b..b45441f9 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php @@ -2,20 +2,67 @@ class Home extends TPage
{
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $data=array('item 1','item 2','item 3','item 4');
+ $this->DBRadioButtonList1->DataSource=$data;
+ $this->DBRadioButtonList1->dataBind();
+
+ $data=array('key 1'=>'item 1','key 2'=>'item 2',
+ 'key 3'=>'item 3','key 4'=>'item 4');
+ $this->DBRadioButtonList2->DataSource=$data;
+ $this->DBRadioButtonList2->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->DBRadioButtonList3->DataSource=$data;
+ $this->DBRadioButtonList3->dataBind();
+ }
+ }
+
+ protected function collectSelectionResult($input,$output)
+ {
+ $indices=$input->SelectedIndices;
+ $result='';
+ foreach($indices as $index)
+ {
+ $item=$input->Items[$index];
+ $result.="(Index: $index, Value: $item->Value, Text: $item->Text)";
+ }
+ if($result==='')
+ $output->Text='Your selection is empty.';
+ else
+ $output->Text='Your selection is: '.$result;
+ }
+
public function buttonClicked($sender,$param)
{
- $index=$this->RadioButtonList->SelectedIndex;
- $value=$this->RadioButtonList->SelectedValue;
- $text=$this->RadioButtonList->SelectedItem->Text;
- $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ $this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult);
}
public function selectionChanged($sender,$param)
{
- $index=$sender->SelectedIndex;
- $value=$sender->SelectedValue;
- $text=$sender->SelectedItem->Text;
- $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ $this->collectSelectionResult($sender,$this->SelectionResult2);
+ }
+
+ public function DBRadioButtonList1Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBRadioButtonList1Result);
+ }
+
+ public function DBRadioButtonList2Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBRadioButtonList2Result);
+ }
+
+ public function DBRadioButtonList3Changed($sender,$param)
+ {
+ $this->collectSelectionResult($sender,$this->DBRadioButtonList3Result);
}
}
|