We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dropdown List with dynamic datasource in Inline Form Template

Thread ID:

Created:

Updated:

Platform:

Replies:

131735 Jul 25,2017 02:23 PM UTC Jul 26,2017 01:54 PM UTC ASP.NET MVC 1
loading
Tags: Grid
CLAUDIO RICCARDI
Asked On July 25, 2017 02:23 PM UTC

Hi,

how can I build a template for inline form editing with a dropdown list control that has a list of values taken from an array?

In other words:

JAVASCRIPT:

    var cLocs = @Html.Raw(Json.Encode(@ViewBag.ContractLocations));
    var contractLocations = [];
    for (var i = 0; i < cLocs.length; i++) {
        contractLocations.push({ id: cLocs[i].LocationId, desc: cLocs[i].ShortDes });
    }

TEMPLATE:

...
            <td>
                <select id="LocationId" name="LocationId">
                    {{for contractLocations}}
                        {{:desc}}
                    {{/for}}
                </select>
            <td>
...

the highlighted part doesn't work...

Thank you.

Claudio

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On July 26, 2017 01:54 PM UTC

 
Hi Claudio,  
 
Thanks for contacting Syncfusion Support.  
 
We can bind dataSource to the DropDown in the ActionComplete event of the Grid as shown in the following code example.  
 
@(Html.EJ().Grid<OrdersView>("Editing") 
        .AllowPaging() 
        .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(90).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID"). Add(); 
            col.Field("Freight").HeaderText("Freight")..Format("{0:C}").Add(); 
           col.Field("EmployeeID").HeaderText("Employee ID").Width(85).Add(); 
        }) 
             .ClientSideEvents(events => 
             { 
                 events.ActionComplete("complete"); 
             }) 
 
) 
 
 
 
<script id="template" type="text/template"> 
    <b>Order Details</b> 
    <table cellspacing="10"> 
               . .  
                   . .  
        <tr> 
            <td style="text-align: right;"> 
                Employee ID 
            </td> 
            <td style="text-align: left"> 
 
                <input type="text" id="EmployeeID" name="EmployeeID" value="{{:EmployeeID}}" /> 
            </td> 
        </tr> 
    </table> 
</script> 
 
<script> 
    var cLocs = @Html.Raw(Json.Encode(@ViewBag.data)); 
    function complete(args) { 
        if (args.requestType == "beginedit" || args.requestType == "add") { 
            $("#Freight").ejNumericTextbox({ value: parseFloat($("#Freight").val()), width: "116px", decimalPlaces: 2 }); 
            $("#EmployeeID").ejDropDownList({ width: '116px', dataSource: cLocs, fields: { value: "EmployeeID", text: "FirstName" } }); 
            if (args.requestType == "beginedit") { 
                $("#OrderID").attr("disabled", "disabled"); 
                $("#EmployeeID").ejDropDownList("setSelectedValue", args.row.children().eq(3).text()); 
            } 
            $(".e-field").css({ 'width': '116px', 'text-align': 'left' }); 
        } 
    } 
</script> 
 
Here dataSource has been bind to the dropdown without any conversion. Since, we have used the text/value pair DropDownList Fields, we didn’t need to convert them. Please make a note that the eq(3) in the ActionComplete event denotes the Column index of the EmployeeID.  
 
Regards,  
Seeni Sakthi Kumar S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;