Linking Grids

Docs

Instances of DbNetGridCore can be linked together to create parent child relationships. To link a child grid simply add it to the parent control using the AddLinkedControl method. The grids are linked by automatically associating the column in the child grid specified as a ForeignKey with the column in the parent grid identified as a PrimaryKey (usually automatic). This sample also demonstrates how to use custom HTML markup by specifyng the Id of the containing element as a 3rd argument to the constructor. It also uses the client-side API method columnValue to update the tab titles for the linked grids.

Razor
                                
                                        
DbNetGridCore orderDetailsGrid = new DbNetGridCore("northwind", "[order details]", "orderDetailsGrid")
{
    Columns = new List{ "OrderID", "ProductID", "Quantity", "UnitPrice", "Discount" },
    PageSize = 10
};

orderDetailsGrid.Column("OrderID").ForeignKey();
orderDetailsGrid.Column("ProductID").Lookup(new Lookup("Products", "ProductId", "ProductName")).Label("Product");
orderDetailsGrid.Column("UnitPrice").Format("c");
orderDetailsGrid.Column("discount").Format("P");

DbNetGridCore ordersGrid = new DbNetGridCore("northwind", "orders", "ordersGrid")
{
    Columns = new List{ "OrderID", "CustomerID", "EmployeeID", "OrderDate", "RequiredDate", "ShippedDate", "ShipVia", "Freight" },
    PageSize = 10
};

ordersGrid.Column("CustomerID").Hidden().ForeignKey();
ordersGrid.Column("EmployeeID").Lookup(new Lookup("Employees", "EmployeeId", "lastname + ',' + firstname")).Label("Employee");
ordersGrid.Column("ShipVia").Lookup(new Lookup("Suppliers", "SupplierId", "CompanyName"));
ordersGrid.Column("Freight").Format("c");
ordersGrid.Bind(EventType.OnRowSelected, "setOrderDetailsTabLabel");
ordersGrid.AddLinkedControl(orderDetailsGrid);

DbNetGridCore customersGrid = new DbNetGridCore("northwind", "customers", "customersGrid")
{
    Columns = new List{ "CustomerID", "CompanyName", "Address", "City" },
    PageSize = 10
};

customersGrid.Column("CustomerID").Hidden();
customersGrid.AddLinkedControl(ordersGrid);
customersGrid.Bind(EventType.OnRowSelected, "setOrderTabLabel");

@customersGrid.Render()