This example demonstrates how to select or deselect rows in a detail grid when master row selection changes.
Follow the steps below to implement master-detail functionality and select or deselect detail rows based on the master row's selection state:
-
Create a master grid control, set the ShowDetailRow property to
true
, specify the grid's Templates.DetailRow property, and add a detail grid to the template. For both grid controls, set the ShowSelectCheckbox property totrue
to enable selection.<dx:ASPxGridView ID="master" runat="server" ...> <SettingsDetail ShowDetailRow="True" /> <ClientSideEvents SelectionChanged="onMasterGridSelectionChanged" /> <Columns> <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" /> <!-- ... --> </Columns> <Templates> <DetailRow> <dx:ASPxGridView ID="detail" runat="server" ...> <Columns> <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" /> <!-- ... --> </Columns> </dx:ASPxGridView> </DetailRow> </Templates> </dx:ASPxGridView>
-
Handle the master grid's client-side SelectionChanged event. In the handler, send a callback to the server and pass the master row's visible index and the row's selection state as parameters.
function onMasterGridSelectionChanged(s, e) { master.PerformCallback("select|" + e.visibleIndex + "|" + (e.isSelected ? "T" : "")); }
-
Handle the master grid's server-side
CustomCallback
event. In the handler, do the following:- Call the master grid's FindDetailRowTemplateControl method to access the detail grid.
- Call the detail grid's SelectAll or UnselectAll method to select or deselect detail grid rows based on the master row's selection state.
protected void master_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { string[] data = e.Parameters.Split('|'); if(data.Length == 3 && data[0] == "select") ProcessDetailSelection(int.Parse(data[1]), data[2] == "T"); } void ProcessDetailSelection(int index, bool state) { ASPxGridView detail = master.FindDetailRowTemplateControl(index, "detail") as ASPxGridView; if(detail != null) { if(state) detail.Selection.SelectAll(); else detail.Selection.UnselectAll(); } }
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Grid View for ASP.NET Web Forms - Simple master-detail implementation
- Grid View for ASP.NET Web Forms - How to update master and detail grids simultaneously in batch edit mode
- Grid View for ASP.NET Web Forms - How to refresh a master grid on a detail grid callback
(you will be redirected to DevExpress.com to submit your response)