Dailycode.info

Short solution for short problems

Devexpress master-detail ASPxGridView: selected records in the detail grid.

 

I had following scenario:

An aspx page with some devexpress grids. The goal was to use a master detail grid, where I could select a record in the master grid, then select a record in the detail grid. Then I press an install button where I get the selected records and save them to the database.

Showing the grids was no problem, getting the selected master grid line was also very easy. But then the challenge came, getting the selected record in the detail grid. I couldn’t find it working in server side code.  There were a lot of examples on how to fill up a detail grid or how to collapse or expand records in a detail grid, but no real examples on how to get the selected records in a detail grid.

At the end of my frustration, I decided to use 3 separate grids and let the 3rd function as a detail grid. Now it’s working fine. The devexpress way of showing a detail grid inside a master grid, was a very nice feature, but not working for this case. So the way I solved it now is to handle the row-focused event in the master grid, check some data and show the detail grid if necessary.

Here you have the screen example of how I solved it now:


 

If a record is selected that has detail records, then I show the detail grid. In this grid, its possible to select a record and perform actions, like uninstall it.


To get the focused row working on server side, you need to configure some things on the grid. The  most important settings are:

	    ClientIDMode="AutoID" OnFocusedRowChanged="grdMaster_FocusedRowChanged"
            SettingsBehavior-AllowFocusedRow="true" SettingsBehavior-AllowMultiSelection="false"
            SettingsBehavior-ProcessFocusedRowChangedOnServer="true" EnableRowsCache="false" EnableCallBacks="false" SettingsBehavior-ProcessSelectionChangedOnServer="true"

Then this is the code to use if you want to get the selected records from the grids: (The first 2 lines get the selected record from the master grid, the second 2 lines get the selected record from the detail grid (3rd grid))

 

string[] sfield = { "ID" };

string softID = Convert.ToString(grdSoftwareOverview.GetRowValues(grdSoftwareOverview.FocusedRowIndex, sfield));


string[] sfieldLic = { "SoftwareLicenseID" };

string selectedItemLic = Convert.ToString(grdLicenseOverview.GetRowValues(grdLicenseOverview.FocusedRowIndex, sfieldLic));