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

[Solved] how to populate one dropdownlist on change event of other dropdownlist in grid

2 Answers 118 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
saroj
Top achievements
Rank 1
saroj asked on 09 Feb 2012, 07:09 AM
I have a grid inside which i have two dropdown lists.
I want the functionality by which if i change value of first ddl then related to that value, second ddl should populate.

Change event of first ddl is fired but what to write inside that jquery.
Simultaneously I am using editor template for both ddls.

i am doing smthing like this but not working:

function onTypeChange(e) {
var idDept = 2; 
            getBranches(idDept);
    }   
    function getBranches(idDept){

        $.ajax({
            url: "@Url.Action("GetBranchList", "FleetEdit")",
            data: {departmentId: idDept},
            dataType: "json",
            type: "POST",            
            success: function (myData){
                var items= "";
                items += "<option value=\"\">" + "" + "</option>";

                $.each(myData, function(i,item){
                    items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
                });
                $('#Parentform.t-edit-form').find('#Fleet').closest('div.t-dropdown').html(items);
            }
        });
    }

Fleet is the name of editor template of second ddl.

Please reply soon if anybody has the solution...!!!
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 10 Feb 2012, 03:18 PM
Hi Saroj,

I attached a sample project which implements a Grid with two columns which are using DropDownList for editor templates. The OnChange event of the first makes a request to the server which result is used to populate the data of the second DropDownList.
I hope this helps you, use it as a base point for more complex logic.

All the best,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
saroj
Top achievements
Rank 1
answered on 13 Feb 2012, 01:29 AM
Hi Petur

Thank you very much for your quick reply which works perfect as I wanted.
Thanks again.
Tags
General Discussions
Asked by
saroj
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
saroj
Top achievements
Rank 1
Share this question
or