Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > onChange event of dropdownlist in grid

Not answered onChange event of dropdownlist in grid

Feed from this thread
  • Niroj avatar

    Posted on Feb 2, 2012 (permalink)

    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. 

    Reply

  • Daniel Daniel admin's avatar

    Posted on Feb 6, 2012 (permalink)

    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 >>

    Reply

  • Niroj avatar

    Posted on Feb 6, 2012 (permalink)

    Thanks Daniel..
    Solved myself by writing proper jQuery.

    Thanks.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > onChange event of dropdownlist in grid