Tags

, ,


how to make the multiple dropdown list can be selected in update option ?

ANS:

As I am getting the value dynamical, So, I have to make the list dynamically according to databases saved id and following yii convention…$result = Product::model()->findAllBySql($query);

                $selectedlist = CHtml::listData($result,’ProductID’, ‘ProductID’);
$x =  array();
foreach ($selectedlist as $key => $value) {
//$selectedlist[$key]=’array(“selected”=>”selected”)';
$x[$key]=array(“selected”=>”selected”);
}$list=CHtml::listData( Product::model()->findAllBySql(SELECT ProductID, ProductName
FROM product ORDER BY ProductName ASC’),’ProductID’, ‘ProductName‘);

echo $form->dropDownList($model,’ClientIDs’,$list, array(  ’empty’=>’——Select multiple clients——‘,

    ‘options’=>$x,
                ‘size’=>”5″,
                ‘value’ => ‘Y’,
                ‘uncheckValue’=>’N’,
               //’name’=>’categoryList’,
                ‘multiple’=>’multiple’,
                ‘style’=>’width:250px;’)
);

============================== Another way==========

But, in this way, you will able to make the items selected but, that value you will not able to use, when update.

This is:

echo Chtml::dropDownList(‘ClientIDs’,$selected, $list, array(  ’empty’=>’——Select multiple clients——‘,));

About these ads