Skip to content

DevExpress-Examples/asp-net-web-forms-grid-select-detail-rows-on-master-row-selection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - Select detail rows on master row selection

This example demonstrates how to select or deselect rows in a detail grid when master row selection changes.

Select Rows in Detail Grid

Overview

Follow the steps below to implement master-detail functionality and select or deselect detail rows based on the master row's selection state:

  1. 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 to true 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>
  2. 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" : ""));
    }
  3. Handle the master grid's server-side CustomCallback event. In the handler, do the following:

    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();
    	}
    }

Files to Review

Documentation

More Examples