Following on the CSLA databinding theme, I ran into an interesting problem on databinding a parent/child CSLA business object relationship with Telerik's radGrid control. The solution is certainly not obvious, but the implementation ends up being pretty straight forward.
First, I set up two distinct CslaDataSource controls – one for each collection. In reality, these are part of the same object hiearchy and I could do this with one control, but I feel it comes out a little cleaner with two.
The key points to consider are this:
- Grid: Set the MasterTableView and DetailTable DataSourceIds to their respective CSLA data binding control (dbc).
- Grid: Set the MasterTableView's DateKeyNames property to reflect the unique identifier for the parent row.
- DBC Parent: Set up the DataSource_SelectObject to return the business object via the e.BusinessObject parameter.
- Grid: Map the ItemCommandEvent to grab parent key using the code snippet below.
- DBC Child: Set up the DataSource_SelectObject to return the appropriate child object according to the key obtained in step #4.
Below is the code snippet for the Grid_ItemCommand event mentioned above:
private Guid ActiveParentId = Guid.Empty; //data type may vary for actual implementation.
protected void …_ItemCommand(…)
if( e.CommandName == ExpandCollapseCommand )
ActiveParentId = (Guid) e.Item.OwnerTableView.DataKeyValues[e.Item.Index][parentIdName];