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

[Solved] Ajax binding to DataTable - Help !

1 Answer 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 16 May 2012, 04:15 PM
Hi,

I am unable to use Ajax binding with a DataTable, I've followed all the online examples and keep getting the error:

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

Here is my View:

@(Html.Telerik().Grid(Model.Data)
                .Name("LoanPurposesGrid")
                .ToolBar(commands => commands.Insert())
                .DataBinding(dataBinding => {
                    dataBinding.Ajax()
                    .Select("_select", "ProgramManagement")
                    .Insert("AddFinancingElementGrid", "ProgramManagement")
                    .Update("UpdateFinancingElementGrid", "ProgramManagement")
                    .Delete("DeleteFinancingElementGrid", "ProgramManagement");
                })
 
                .Columns(columns =>
                {
                    columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>);
 
                    columns.Command(commands =>
                    {
                        commands.Edit().ButtonType(GridButtonType.BareImage); 
                        commands.Delete().ButtonType(GridButtonType.BareImage);
                    }).Width(110).Title("Action");
                })
         
                .EnableCustomBinding(true)
                .Footer(false)
                .Sortable()
 
)

and the Controller Action/View Model:

public class TestModel
     {
         public DataTable Data { get; set; }
         public IEnumerable<GridColumnSettings> Columns { get; set; }
     }
 
     public GridColumnSettings[] columns()
     {
         GridColumnSettings[] columns = new[] 
             
                 new GridColumnSettings { Member = "Id", Width = "130px", Title="Id"},
                 new GridColumnSettings { Member="Number", Title="Number",  Width = "130px"},
                 new GridColumnSettings { Member = "Description", Width = "130px", Title="Description"},
             };
         return columns;
     }
 
     public ActionResult Index()
     {
         DataTable table = new DataTable();
         table.Columns.Add("Id");
         table.Columns.Add("Number");
         table.Columns.Add("Description");
 
         DataRow row = table.NewRow();
 
         row[0] = 1;
         row[1] = 2;
         row[2] = "Description 1";
 
         table.Rows.Add(row);
 
         row = table.NewRow();
         row[0] = 2;
         row[1] = 3;
         row[2] = "Description 2";
 
         table.Rows.Add(row);
 
         TestModel model = new TestModel() { Data = table, Columns = columns() };
 
         return View(model);
     }

Paul

1 Answer, 1 is accepted

Sort by
0
Flappie
Top achievements
Rank 1
answered on 18 May 2012, 01:02 PM
I was looking for the exact same thing, and then stumbled on this answer:

"Unfortunately inline editing with datatable is not supported because ASP.NET MVC cannot generate an editor for a grid column (Html.EditorFor(row => row.Property)) when the model is a datarowview. You can however use popup and inform editing as shown in this code library project."
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Flappie
Top achievements
Rank 1
Share this question
or