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

[Solved] GridBindingToDataTableSample; Modify to add columns from any arbitrary ADO.NET DataTable

0 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Radoslav Radivojevic
Top achievements
Rank 1
Radoslav Radivojevic asked on 20 Dec 2010, 09:36 PM
I need to create CRUD screens for an arbitrary DataTable (using ADO.NET). 
Imagine that I will have some metadata TableColumnMedatata table that will contain Table/Column metadata:
table    column        type     length    pk
=============================================
EmpLoc   EmployeeID    int     4         1
EmpLoc   LocID         int      4         1
---------------------------------------------




Orders   OrderID       int      4         1
Orders   CustomerID    nchar    10        0
Orders   EmployeeID    int      4         0
Orders   OrderDate     datetime 8         0
Orders   ShipVia      int      4         0
Orders   Freight       money    8         0
Orders   ShipName      nvarchar 80        0
---------------------------------------------
Employees EmployeeID   int      4         1
Employees LastName     nvarchar 40        0
Employees FirstName    nvarchar 20        0


...
I would need to add datatable columns and datakeys (notice EmpLoc table has 2 composite keys) dynamically
using MVC Grid helper like this:
    .DataKeys(dataKeys =>
    {
        foreach (string compositeKeyPart in TableColumnMedatata.Keys)
        {
            dataKeys.Add(compositeKeyPart ));
        }

      }
and I would need to add columns like shown in the code below. I would need to add TableColumnMedatata (table or class) to DataTableViewModel to be available in the view.

What should I enter for "??????" (instead "ProductItem" as in the sample code)
to enable edit form for any arbitrary table i select from let's say a combo box?
What else I am missing
















<
asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>
        Server Binding
    </h3>
    <%= Html.Telerik().Grid(Model.Data)
                  .Name("Grid")     
                  .DataKeys(dataKeys => dataKeys.Add("ProductID"))
                  .ToolBar(toolBar => toolBar.Insert())
                  .Columns(columns =>
                               {
                                    foreach (string column in TableColumnMedatata.Columns)
                                    {
                                        if (column.PK)
                                           
columns.Bound(coulumn.name).ReadOnly();
                                        else
                                            columns.Bound(column.name)
                                    }
                                   columns.Command(command =>
                                                       {
                                                           command.Edit();
                                                           command.Delete();
                                                       });
                               })
                  .DataBinding(dataBinding => dataBinding.Server()
                                                         .Update("UpdateDataTableBinding""Home")
                                                         .Delete("DeleteDataTableBinding""Home")
                                                         .Insert("InsertDataTableBinding""Home"))
                  .Editable(editable => editable.TemplateName("??????").Mode(GridEditMode.InForm))
                  .Pageable()
                  .Sortable()
                  .Filterable()
                  .Groupable()
    %>
</asp:Content>



Thank you,
Rad
Tags
General Discussions
Asked by
Radoslav Radivojevic
Top achievements
Rank 1
Share this question
or