aspnetbootstrap-118114-grid-view-master-detail-relationship-master-detail-implementation.md
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.
To retrieve data from the database, use the SqlDataSource components:
Master : Categories
Detail : Products. Define a filter rule (see the image below).
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.
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.
using DevExpress.Web.Bootstrap;
protected void detailGrid_BeforePerformDataSelect(object sender, EventArgs e) {
Session["CategoryID"] = (sender as BootstrapGridView).GetMasterRowKeyValue();
}
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.