summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php
blob: 682b2d45b953575ea9bfa036e2b9a0d021977908 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

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)
	{
		$this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult);
	}

	public function selectionChanged($sender,$param)
	{
		$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);
	}
}