Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

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];
}

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Leave a Reply