This question is locked. New answers and comments are not allowed.
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 =>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.{
foreach (string compositeKeyPart in TableColumnMedatata.Keys)
{
dataKeys.Add(compositeKeyPart ));
}
}
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