There are scenarios in which you may want to present dependant grids (filtering
the records in the second grid according to the selection in the first) to enrich the user
experience and make the interaction between these grid easier and more intuitive. r.a.d.
grid supports this feature out-of-the-box in a similar means as the MS GridView.
In the demo above the first grid presents
Customers and the second grid visualizes the
relevant
Orders for the selected customer. The main points for attaining this behavior
are:
- add the primary key field for the first grid to the DataKeyNames array of its
MasterTableView
- construct SelectParameter of type ControlParameter for the second grid data
source control. The ControlID of that SelectParameter should point to the first
grid, the Name property should match the primary key value added previously as first
to the DataKeyNames array, the PropertyName should be SelectedValue.
You can also add DefaultValue and Type attributes as presented below:
<asp:AccessDataSource ID="AccessDataSource2" DataFile="~/Grid/Data/Access/Nwind.mdb"
SelectCommand="SELECT [OrderID], [OrderDate], [CustomerID], [ShipCountry] FROM [Orders] WHERE ([CustomerID] = ?)"
runat="server">
<SelectParameters>
<asp:ControlParameter ControlID="RadGrid1" DefaultValue="ALFKI" Name="CustomerID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
- in addition on paging the first item of the new page is selected and the second
grid is rebound respectively. The code on the server do this job (Grid_PageIndexChanged,
Grid_PreRender event handlers).
The functionality depicted beforehand is enhanced to be performed with asynchronous requests
(wiring the
OnRowClick/OnRequestStart/OnRequestEnd events of the grid). The row
selection is made through keyboard navigation - check the
Accessibility section for
more details.