Master-Detail: Implementation

  • 2 minutes to read

In this document, you will learn how to use the Bootstrap Grid View to display master-detail data. Data is obtained from the Categories and Products tables in the NWind database. The Categories table is the master, while Products is a detail table. A master-detail relationship is established through the CategoryID field.

  1. Retrieve Data From the Database
  2. Create Master and Detail ASPxGridViews
  3. Set up a Master-Detail Relationship

1. Retrieve Data From the Database

To retrieve data from the database, use the SqlDataSource components:

  • Master: Categories

    BootstrapGrid_MasterDetail_MasterDataSource

  • Detail: Products. Define a filter rule (see the image below).

    BootstrapGrid_MasterDetail_DetailDataSource

2. Create Master and Detail ASPxGridView

Create two BootstrapGridView controls. Bind the first grid (master) to the dsCategories. Bind the second grid (detail) to the dsProducts. Specify data source key fields for both grids using their ASPxGridBase.KeyFieldName property.

3. Set up a Master-Detail Relationship

Invoke BootstrapGridView's Template Designer by clicking the Edit Templates task. Select the DetailRow template.

BootstrapGrid_MasterDetail_DetailRowTemplate

Drag the detail grid onto the Detail Row template.

BootstrapGrid_MasterDetail_DetailGrid

Handle the ASPxGridBase.BeforePerformDataSelect event to specify session values.


using DevExpress.Web.Bootstrap;

protected void detailGrid_BeforePerformDataSelect(object sender, EventArgs e) {
    Session["CategoryID"] = (sender as BootstrapGridView).GetMasterRowKeyValue();
}

When finished, select the End Template Editing task and enable the master grid's ASPxGridViewDetailSettings.ShowDetailRow option.

The image below illustrates the result.

BootstrapGrid_MasterDetail_Result