I have a form with dropDownList
I need to pass the data from DB to that list.
$form->dropDownList($model,'parent',$dd_data); ?>
Where and how should I define $dd_data array?
You can use CHtml::listData to populate $dd_data, directly in the view, or use it in the controller and pass it to the view.
$dd_data array needs to be of format: array('value'=>'display') check CHtml::dropDownList().
Related
I have an input and I want to populate the shortDesc atttribute with the value of another attribute of the View Object, how can I do it?
Thanks in advance.
In the bindings on the page, create an attributeValues binding to the View Object. Then in shortDesc property, it will be:
shortDesc="#{bindings.nameOfAttributeValuesBinding.inputValue}"
As the View Object goes to a given row, the attributeValues binding updates with the value. You may need to put a partial trigger on the component so it will update when a UI action takes place depending on what you are doing.
In Yii, I listed my table which is fetch from database in grid view.
'value'=> 'CHtml::radioButton("set_default",false,array(
"value"=>"$data->id",
"set"=>"1",
"disable"=>"disable",
"uncheckValue"=>null
))',
the above code I entered in normal radio button view, how do I fetch from database? Anybody help me?
CGridView lets you write any value inside row's column instead of normal database values. For modify column values, you need to add a function for value attribute. Inside of this function, you can access each data's attributes. In your case, You need to echo a radio button like this:
//$data refres to each data row in the CGridView
'value' => function ($data, $row) {
echo
CHtml::radioButton("set_default",false,array(
"value"=>$data->id,
"set"=>"1",
"disable"=>"disable",
"uncheckValue"=>null
)),
},
I have a single razor view in which i am trying to implement both Create and Edit options. Here is cshtml code for a drop down field:
#Html.DropDownListFor(model => model.StateID, (SelectList)ViewBag.StateID, "--Select--", new { #Id = "ddlState" })
However in edit mode although all the other fields are populated as per the model, the dropdown is not showing the saved selected value as per the model. I have used a viewbag to populate the dropdown and that works fine. The states are populated in the dropdown.
ViewBag.StateID = new SelectList(queryStatesInLookup, "LookupID", "LookupCode")
I debugged the razor page and checked. I get the state id from the model (for eg: 8), but this value wont bind to the dropdown. What gives? :/
Apparently the Viewbag cannot have the same name as the property the model ID is bound to. My guess is the CLR is unable to resolve the conflicting names of the dynamic object type Viewbag and the model property name at run time. Thanks :)
When you create your SelectList, you need to pass in the selected value there.
In the example below, replace SelectedValue with your actual selected value.
ViewBag.StateID = new SelectList(queryStatesInLookup, "LookupID", "LookupCode", SelectedValue)
I have a drop down list in a view bind to a model (MVC4)
#Html.DropDownList("ID_ROLE", String.Empty)
ID_ROLE is one of the property of the model
and ID_ROLE is also the name of the viewbag I pass to the view in this way
ViewBag.ID_ROLE = new SelectList(lista_ruoli.OrderBy(x => x.DESCR_ROLE), "ID_ROLE", "DESCR_ROLE", user_to_edit.ID_ROLE);
In this way it works..
but I don't understand why I can't find an extension of the HtmlHelper.DropDownList
which fits with
#Html.DropDownList("ID_ROLE", String.Empty)
Is this way wrong or not?
Thank you!
Not sure if I understand correctly, but if you want the list to show up in the dropdown, you need to provide the list to the HTML helper:
#Html.DropDownList("ID_ROLE", (SelectList)ViewBag.ID_ROLE)
I am using a multi form model. A $model array is passed to the view and for each model object I am trying to have an errorsummary. See the code below.
foreach ($model as $f=>$edu):
echo $form->errorSummary($edu,'');
echo $form->textField($edu,"[$f]schoolname",array('size'=>30,'maxlength'=>128));
endforeach;
When I submit the form an error summary for only one form is displayed. Any ideas.
Maybe you need to rethink your form structure, for example - put all into one form, then inside controller make validation of every model you use and then show error messages.