-2

i have the following code in my view:

<?=Html::dropdownList('region',null,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
        'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
and submit button

 <?= Html::submitButton('Search', ['name' => 'dele','class' => 'btn btn-primary']) ?>

my code working well but I have one big problem. I select a region and click the search button, the result comes correctly, and 10 result is shown per page when I click the next page, it gives me false data, I notice this is due to the selected value on the dropdownlist is reset. I tried both making " Selected'=> true, and 'Selected'=>'selected', but it does not work. so how can I make the selected value on dropdownlist and checkboxlist will be selected after the page is loading? thanks

Mehran
  • 282
  • 1
  • 6
  • 17
girmay
  • 3
  • 2

1 Answers1

1

It is very simple, you must pass integer $region_id only:

<?=Html::dropdownList('region', $region_id,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
        'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • i tried to give the primary key of the ethioregion table that is id, i modified my code like this =Html::DropDownList('region','id', ArrayHelper::map(Ethioregion::find()->all(),'id','region'),['Selected'=>'selected', 'prompt' => 'Select Region..','style'=>'width:200px',]) ?> and i tried 'Selected'=>true, but still not working, when the button is clicked i just want to keep the selected value untill i select other, how can i show this using activedropdownlist, or using this dropdownlist code? thanks for ur help – girmay Dec 24 '18 at 04:48