I'm developing web application by ASP.NET-MVC.
Model:
public partial class MyModel
{
public string TEST { get; set; }
}
Html:
@model IList<MyModel>
@Html.DropDownList("dropDownListSelectToAnotherDropDownList", (SelectList)ViewBag.testList[0], null, new { id = "dropDownListSelectToAnotherDropDownList", title = "[--Select to all--]", @class = "selectpicker form-control", data_style = "btn btn-default", data_width = "100%", data_live_search = "true", data_size = "9" })
@for (var i = 0; i < Model.Count; i++)
{
@Html.DropDownListFor(m => Model[i].TEST, (SelectList)ViewBag.testList[i], null, new { id = "dropDownListTest" + i, title = "[--Select Test--]", @class = "selectpicker form-control", data_style = "btn btn-default", data_width = "100%", data_live_search = "true", data_size = "9" })
}
jQuery:
$('#dropDownListSelectToAnotherDropDownList').on('keyup change', function () {
@for (var i = 0; i < Model.Count; i++)
{
$('dropDownListTest' + i).val($(this).val());
//$('dropDownListTest' + i).selectpicker('val', $(this).val());
}
});
As the code above, I will get dropDownListSelectToAnotherDropDownList and many dropDownListTest (For example: dropDownListTest0, dropDownListTest1, ..., dropDownListTestN) that depends on count of model. I want to create event when dropDownListSelectToAnotherDropDownList is change. The event will get data from dropDownListSelectToAnotherDropDownList and then set to all dropDownListTest. But it's not work. Could someone help to suggested me, please?