Linked Edit

Docs

An editing capability can also be added to DbNetGrid by explicity linking instances of DbNetEdit using the AddLinkedControl method. In this sample the ability to edit the selected customer record itself and also order records for the selected customer. For one-to-many relationships it is necessary to specify the column in the linked control that acts as the foreign key using the ForeignKey method. The sample also uses the OnRowSelected client-side event to update the tab labels with the selected customer name.

Razor
                                
                                        
DbNetEditCore customersEdit = new DbNetEditCore("northwind", "customers", "customersEdit");
customersEdit.LayoutColumns = 2;
DbNetEditCore ordersEdit = new DbNetEditCore("northwind", "orders", "ordersEdit");
ordersEdit.LayoutColumns = 2;
ordersEdit.Column("CustomerId").ForeignKey();
ordersEdit.Column("ShipVia").Lookup(new Lookup("Shippers","ShipperID", "CompanyName"));
ordersEdit.Column("EmployeeId").Lookup(new Lookup("Employees", "EmployeeID", "FirstName + ' ' + LastName")).Label("Employee");
ordersEdit.Column("Freight").Format("c");

DbNetGridCore customersGrid = new DbNetGridCore("northwind", "customers", "customersGrid") { PageSize = 10 };
customersGrid.Columns = new List() { "CustomerId", "CompanyName",  "ContactTitle", "Address", "City", "Region", "Country" };
customersGrid.Labels = new List() { "", "Company Name",  "Contact", "Address", "City", "Region", "Country" };
customersGrid.Column(new string[] { "Addr", "PhoneFax" }).Style("text-align:left");
customersGrid.Column("CustomerId").Hidden();
customersGrid.AddLinkedControl(customersEdit);
customersGrid.AddLinkedControl(ordersEdit);
customersGrid.Bind(EventType.OnRowSelected, "setTabLabels");

@customersGrid.Render()