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

How to populate Dropdownlist in Grid ClientTemplate code?

1 Answer 423 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 28 Feb 2017, 02:16 PM

I am trying to use a ClientTemplate containing a DropDownListFor in a grid. My ClientTemplate code is as follows: 

@(Html.Kendo().DropDownListFor(m => m)
        .DataValueField("Value")
        .DataTextField("Text")
        .Name("PurchaseAgreementType")
        .BindTo(new List<SelectListItem>() {
            new SelectListItem() {
                Text = "PO Only",
                Value = "PO Only"
            },
            new SelectListItem() {
                Text = "Contract Based",
                Value = "Contract Based"
            }
    }))

the column in the grid is shown here: 

                    columns.Bound(l => l.PurchaseAgreementType).ClientTemplate("#=PurchaseAgreementType.Value#").Width(150);

This results in the following error: Uncaught TypeError: Cannot read property 'Value' of null

However if I copy/paste the code in the client template directly onto my form, it works perfectly.  
How can I get this to work in my grid? It seems that the DDL is not populating. 

Thanks. 

 

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 02 Mar 2017, 09:31 AM
Hелло Xavier,

As I can see from the stated error that is thrown - the reason is probably the scenario when the value field is null. Hence, you can try the following implementation for the ClientTemplate evaluation:

columns.Bound(l => l.PurchaseAgreementType).ClientTemplate("#= PurchaseAgreementType.Value != null ? PurchaseAgreementType.Value : ' ' # ").Width(150);

If the above does not help. I would like to ask you to provide us with a runnable sample, in order to investigate the exact scenario when the implementation fails with the described error and pin down the reason for it.

Hope this would help.

Regards,
Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Xavier
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or