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

onChange event of dropdownlist in grid

2 Answers 257 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.
Howard
Top achievements
Rank 1
Howard asked on 02 Feb 2012, 06:15 AM
I have a dropdownlist, textboxes in grid.
now, i want if i change the value of dropdownlist it should come up with relative value of the textbox at edit and insert time.
my code is as follows:

view:

@(Html.Telerik().Grid<FleetParentChildQueryModel>()
    .Name("Parent")
    .ToolBar(commands =>
    {
        commands.Insert().ButtonType(GridButtonType.Text).HtmlAttributes(new { @style = "color: black;" });
    })
    .DataKeys(keys => keys.Add(c => c.FLEET_ID))

    .Columns(columns =>
    {
        columns.Bound(c => c.FLEET_ID).Title("Parent Fleet Code").ClientTemplate("<#=FLEET_USER_CODE #>");
        columns.Bound(c => c.REGISTRATION).Title("Registration");
        columns.Bound(c => c.ASSET_NUMBER).Title("Asset No");
        columns.Bound(c => c.DATE_OF_ASSOCIATION).Title("Association Date").Format("{0:dd/MM/yyyy}");       
        columns.Bound(c => c.DATE_OF_DISASSOCIATION).Title("Disassociation Date").Format("{0:dd/MM/yyyy}");
        columns.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.Text);


        }).Width(200).HeaderHtmlAttributes(new { @style = "font-weight:bolder;" }).Title("Commands");
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_FleetParent", "Fleet", new { Id = ViewData["FLEET_ID"] })
                                                   .Insert("_FleetParentInsert", "FleetInsert", new { Id = ViewData["FLEET_ID"] })
                                                                           .Update("_FleetParentEdit", "Fleet"))
    .Pageable()
    .Sortable()
    .Selectable()
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .ClientEvents(events => events.OnEdit("onEdit")).HtmlAttributes(new { @style = "color: black;" })
    )

editor template:

@(Html.Telerik().DropDownList()
            .Name("Fleet")
                .BindTo(new SelectList((System.Collections.IEnumerable)ViewBag.Fleets, "FLEET_ID", "FLEET_USER_CODE"))
                .ClientEvents(events=> events
                    .OnChange("onChange"))
    )

i dont know how to write jquery for this.

<script type="text/javascript">
    function onChange(e) {

// ???
    }
</script>

Any help will be greatly appreciated. 

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Feb 2012, 12:29 PM
Hello Niroj,

To modify the values when performing edit or insert in the Grid based on the DropDownList selection, you should handle the OnEdit client-side event and change them manually. For example:
function onEdit(e) {
    var selectedValue = $("#Fleet").data("tDropDownList").value();
    // find the elements in the editor form and change the values
}


Greetings,
Daniel
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
Howard
Top achievements
Rank 1
answered on 07 Feb 2012, 01:13 AM
Thanks Daniel..
Solved myself by writing proper jQuery.

Thanks.
Tags
General Discussions
Asked by
Howard
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Howard
Top achievements
Rank 1
Share this question
or