Back to Devexpress

Master-Detail: Implementation

aspnetbootstrap-118114-grid-view-master-detail-relationship-master-detail-implementation.md

latest2.6 KB
Original Source

Master-Detail: Implementation

  • Oct 29, 2020
  • 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

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

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.

Drag the detail grid onto the Detail Row template.

Handle the ASPxGridBase.BeforePerformDataSelect event to specify session values.

csharp
using DevExpress.Web.Bootstrap;

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

Protected Sub detailGrid_BeforePerformDataSelect(ByVal sender As Object, ByVal e As EventArgs)
    Session("CategoryID") = (TryCast(sender, BootstrapGridView)).GetMasterRowKeyValue()
End Sub

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

The image below illustrates the result.