Question

I have a dynamic dropdown, data coming from the database.

 <?php $sel_id = $selected_id_array[0]->UPR_RelationType;?>

My dropdowm looks like this

 <?php echo    CHtml::dropDownList('RelationType_'.$pat_id[0]->PAT_ID,'U2U_RelationType',CHtml::listData(MasterTypeItems::model()->findAllByAttributes(array('MSTT_MST_ID'=>$relationship_type_array[0]->MST_ID),array('order' => 'MSTT_Name')), 'MSTT_ID', 'MSTT_Name'),array('id'=>'select','class'=>'relation_type','style'=>'width:50px'));

In this dropdown i have to select defaultly $sel_id;

for example am getting $sel_id=5; In the drop down i have to select 5th option as selected in yii. please give me any suggestion what i have to write in dropDown to select $sel_id;

Was it helpful?

Solution

If I understand your question correctly, what you want to achieve is a dropdownlist which already has a pre-selected option. If so, then this piece of code should work.

echo dropDownList(string $name, string $select, array $data, array $htmlOptions=array ( ))

where $select would be your default selected item.

More information can be found here: http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top