CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Steve Hebert's Development Blog

Steve's Blog - From .Net to dotMath and everything in between.

Hiearchical data binding with CSLA and Telerik's radGrid control.

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:

  1. Grid: Set the MasterTableView and DetailTable DataSourceIds to their respective CSLA data binding control (dbc).
  2. Grid: Set the MasterTableView's DateKeyNames property to reflect the unique identifier for the parent row.
  3. DBC Parent: Set up the DataSource_SelectObject to return the business object via the e.BusinessObject parameter.
  4. Grid: Map the ItemCommandEvent to grab parent key using the code snippet below.
  5. 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];
}



Check out Devlicio.us!

Our Sponsors