Вопрос

Someone pointed me to Kendo Bind to Data Table, which has this code in the grid builder:

.Columns(columns =>
{
    foreach (System.Data.DataColumn column in Model.Columns)
    {
        columns.Bound(column.ColumnName);
    }
})

This works, but I also want to add an "edit" column, so I added this line before the foreach:

columns.Command(command => command.Edit().Text("Edit").UpdateText("Submit")).Width(70).HtmlAttributes(new { style = "text-align: right;" });

which throws "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."

How can I add an Edit column?

Это было полезно?

Решение

As it turns out, "How can I add an Edit column?" is the wrong question. There is nothing wrong with the code to add the Edit command; however, adding it surfaced the problem that was reported. In other words, the "Template" in the error message is the Edit template which doesn't know what column in the DataTable to use for its Id.

When defining the DataSource for the grid, I had this code:

                .Model(model => 
                {
                    foreach (System.Data.DataColumn column in Model.Columns)
                    {
                        model.Field(column.ColumnName, column.DataType);
                    }                
                })

as defined in a sample in a Telerik support forum. This was OK for simply displaying the data in a grid, but when I introduced the idea of Editing, it then mattered that there was no Model.Id. The question then became, how do I define an Id when the Model is a DataTable. That is a separate question, which I have posted here.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top