This is a migrated thread and some comments may be shown as answers.

Load Dropdown based on radio button selected.

3 Answers 397 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 08 Oct 2012, 06:37 AM
Hello,

I am new to kendo and MVC3,
could you please know how to bind the drop-down list based on the radio button value selected.

Thanks in advance.

Regards,
Ravi

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Oct 2012, 06:47 AM
Hello,

Please try with below link.

http://www.kendoui.com/forums/ui/dropdownlist/dropdownlist-datasource-binding-help.aspx


$(document).ready(function () {
 $('input[id="YourRadioButtonID"]').each(function () {
            $(this).bind("click", function () {
 
// Your Ajax call code comes here
 
            });
        });
 });



Thanks,
Jayesh Goyani
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Oct 2012, 09:52 AM
Hello,

Another Solution.

.cshtml

<script type="text/javascript">
    $(document).ready(function () {
 
        $('input[id="CoutryID"]').each(function () {
            $(this).bind("click", function () {
                BindStateCombo($(this).val());
            });
        });
 
 
    });
 
 
    function BindStateCombo(CoutryID) {
 
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "YourDomain" + "VendorAccount/GetStateByCountry",
                    data: {
                        Value: CoutryID
                    }
                }
            }
        });
 
        var ddl = $('#StateID').data("kendoDropDownList");
        ddl.setDataSource(dataSource);
        ddl.refresh();
    }
 
</script>

<div>
    @if (Model.Countries != null && Model.Countries.Count > 0)
    {
        foreach (var radioitem in Model.Countries)
        {
        @Html.RadioButtonFor(model => model.CoutryID, radioitem.CountryID);
         
        @radioitem.CountryName;
        <br />                                                                                 
        }
    }
    <br />
    @(Html.Kendo().DropDownListFor(model => model.StateID)
                    .Name("StateID")
          .OptionLabel("--Select--")
                  .DataTextField("StateName")
                  .DataValueField("StateID")
    )
</div>

Controller
public JsonResult GetStateByCountry(string Value)
        {
            int CountryID = 0;
 
            if (!string.IsNullOrEmpty(Value))
            {
                CountryID = Convert.ToInt32(Value);
            }
             
 
            var dataitem = new List<Data.Country>(); // Do your logic here
            return Json(dataitem, JsonRequestBehavior.AllowGet);
        }


Model
public class AddCoverageArea
    {
        public string CoutryID { get; set; }
        public string StateID { get; set; }
      
        public List<Country> Countries { get; set; }
       
      
    }


Thanks,
Jayesh Goyani
0
Ravi
Top achievements
Rank 1
answered on 06 Nov 2012, 04:31 PM
Thanks Jayesh
Tags
DropDownList
Asked by
Ravi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ravi
Top achievements
Rank 1
Share this question
or