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

Set value in cascading dropdownlist

1 Answer 643 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mattias Hermansson
Top achievements
Rank 1
Mattias Hermansson asked on 07 May 2014, 10:46 AM
Hello,

I'm trying to set the value of the cascading dropdownlist, i want to set the value that the model have in the second dropdownlist. The value seems to be set, but only after i first click on the second dropdownlist then i get the right "name" in the list. Anything i'm doing wrong?
   <script>
                function contractorChanged() {
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("GetContactPersons", "Permission")',
                        data: {
                            id: $("#ContractorId").val()
                        },
                        cache: false,
                        success: function (data) {
                            $("#ContractorPersonId").data("kendoDropDownList").setDataSource(data);
                       $("#ContractorPersonId").data("kendoDropDownList").value('@Model.ContractorPersonId');
 
                        }
                    });
                }
 
            </script>           
 
@(Html.Kendo().DropDownListFor(model => model.ContractorId)
              .HtmlAttributes(new { style = "width:100%; margin-bottom: 8px;" })
              .OptionLabel("Välj företag")
              .DataTextField("Name")
              .DataValueField("Id")
              .Events(e => e.DataBound("contractorChanged"))
              .DataSource(source =>
              {
                  source.Read(read => { read.Action("GetConstructors", "Permission"); });
              }))
 
            @(Html.Kendo().DropDownListFor(model => model.ContractorPersonId)
              .HtmlAttributes(new { style = "width:100%" })
              .OptionLabel("Välj kontaktperson")
              .DataTextField("FullName")
              .DataValueField("Id")
              .Enable(false)
              .AutoBind(false)
              .CascadeFrom("ContractorId")
            )


1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 08 May 2014, 09:30 AM
Hello Mattias,

In general, the child combobox will try to filter its data source on parent cascade. If the child datasource's is empty after the filtration then its value will be cleared (check this demo, which demonstrates exactly this). I examined the posted code snippet, but I could not notice where the child combobox is bound. Is it with empty data source ? I would also suggest you check the offline demos part of the Telerik UI for ASP.NET MVC bundle. There you can find, examine and debug a cascading demo with remote binding.
If the problem still persists on your end, then I will need a runnable test project to investigate the problem further.

Regards,
Georgi Krustev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DropDownList
Asked by
Mattias Hermansson
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or