0

I am new to frame work. I need to populate the value in dropdownlist.

I used the following code to display the values in dropdown

echo $form->dropDownList($model,'pagetype', $Page_Type); ?>

It displays the options in the dropdown.

I want to populate the selected value in the dropdown list.

The saved values are in $savedValues array.

I dont know how to apply the selected option in the dropdownlist.

3
  • Why do you have a $savedValues array? Do you need to select a value from the dropdown or you want to add other options besides the ones defined in $Page_Type? If you need to mark the selected option, @DCoder answer is absolutely right. Commented Apr 21, 2012 at 9:19
  • I saved some values in Database. The database result is stored in $savedValues array. From this array i want to show the selected value in dropdown. i.e In the drop down i have three options ('one', 'two', 'three'). I choosed option 'two'. So it is saved in database. So while editing the form i need to populate the option 'two' as selected. Commented Apr 21, 2012 at 9:23
  • 1
    You should set $model->pagetype to the selected value (stored in the database), and it will be automatically selected from the list Commented Apr 21, 2012 at 9:34

1 Answer 1

1

Have you read the documentation for CActiveForm::dropDownList ? It determines the selected option automatically, in this case it'll be the one matching $model->pagetype.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes. I already used the following $model->pagetype=$savedvalues['PageType']; But it is not selected the saved option
Can you do a var_dump($Page_Type, $model->pagetype); and add that to your post? It would be helpful to see what html options you're generating.
It results some array. Is there any option to populate the selected value in dropdown

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.