aspnet-3773-components-grid-view-concepts-master-detail-relationship-master-detail-implementation.md
This topic describes how to use the ASPxGridView control to display master-detail data.
The grid obtains its data from the Categories and Products tables in the NWind database. The Categories and Products tables are the master and detail tables, respectively. A master-detail relationship is established through the CategoryID field.
To retrieve data from the database, use the AccessDataSource components:
Master : Categories
Detail : Products. Define a filter rule (see the image below).
Create two ASPxGridView controls. Bind the first grid (master) to dsCategories. Bind the second grid (detail) to dsProducts. To specify data source key fields for both grids, use their corresponding ASPxGridBase.KeyFieldName properties.
Click the smart tag’s Edit Templates task to invoke ASPxGridView’s Template Designer (Template Editing Mode). 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.ASPxGridView;
protected void detailGrid_BeforePerformDataSelect(object sender, EventArgs e) {
Session["CategoryID"] = (sender as ASPxGridView).GetMasterRowKeyValue();
}
Protected Sub detailGrid_BeforePerformDataSelect_
(ByVal sender As Object, ByVal e As System.EventArgs)
Session("CategoryID") = CType(sender, ASPxGridView).GetMasterRowKeyValue()
End Sub
When finished, select the End Template Editing task and set the master grid’s ASPxGridViewDetailSettings.ShowDetailRow property to true.
Alternatively, you can use the ASPxGridView Designer’s Feature Browser to display master-detail data.
The image below illustrates the result.
View Example: Simple master-detail implementation
View Example: How to implement the master-detail functionality with list data sources
View Example: How to display detail grid data in a popup window