I need guidance on how best to create a self-referencing hierarchy grid where the datasource is delegate that returns an IList<>.
Once my mastertables rows are retrieved, I am able to expand the rows, which causes the NeedDatasource event to be fired where I attempt to grab that rows dependent objects and set the datasource to them, but the detail view is always empty.
I am guessing at this point I am going about this the wrong way and am hoping you can point me in the right direction.
Thanks!
Here is the grid:
<
telerik:RadGrid
ID
=
"rgDependentObjects"
runat
=
"server"
AllowCustomPaging
=
"True"
AllowMultiRowSelection
=
"True"
AllowPaging
=
"True"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
OnItemCreated
=
"rgDependentObjects_ItemCreated"
OnDetailTableDataBind
=
"rgDependentObjects_DetailTableDataBind"
>
<
PagerStyle
BackColor
=
"White"
Mode
=
"Advanced"
ShowPagerText
=
"false"
Position
=
"Bottom"
/>
<
MasterTableView
AllowCustomSorting
=
"True"
datakeynames
=
"ParentObject.ID,DependentObject.ID"
EditMode
=
"InPlace"
HierarchyDefaultExpanded
=
"false"
HierarchyLoadMode
=
"ServerOnDemand"
>
<
SelfHierarchySettings
ParentKeyName
=
"ParentObject.ID"
KeyName
=
"DependentObject.ID"
/>
<
Columns
>
<
telerik:GridClientSelectColumn
HeaderText
=
"Delete"
>
<
ItemStyle
Width
=
"6px"
/>
</
telerik:GridClientSelectColumn
>
<
telerik:GridHyperLinkColumn
DataNavigateUrlFields
=
"ParentObject.ID"
DataNavigateUrlFormatString
=
"riskAssetDetail.aspx?LinkID={0}"
DataTextField
=
"ParentObject.Name"
HeaderText
=
"Name"
SortExpression
=
"ParentObject.Name"
>
</
telerik:GridHyperLinkColumn
>
<
telerik:GridBoundColumn
DataField
=
"ParentObjectType"
DataType
=
"System.String"
SortExpression
=
"ObjectType"
HeaderText
=
"Object Type"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowExpandCollapse
=
"true"
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
The Datasource for the mastyer table in rgDependentObject is:
private
IList<TruComply.DomainObjects.ScopeObjectDependency> GetDependentObjectsForAsset(
out
int
totalRecords, TruComply.DomainObjects.Interfaces.ICriteria criteria)
{
//get the collection from the manager and return
//return scopeManager.GetDependentObjectsForAsset(currentAssetID, out totalRecords, criteria);
criteria = CriteriaBuilder.CreateCriteria(ExpressionBuilder.Is(
"DependentObject.ID"
, currentAssetID));
criteria.And(ExpressionBuilder.IsNot(
"ParentObjectType"
,
"AssetGroup"
));
return
scopeManager.GetScopeObjectDependencies(
out
totalRecords, criteria);
}
The NeedDatasource event:
protected
void
rgDependentObjects_DetailTableDataBind(
object
source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
//get the detail vie's parent item
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
if
(e.DetailTableView.Name ==
""
)
{
int
totalRecords = 0;
ICriteria criteria = CriteriaBuilder.CreateCriteria(ExpressionBuilder.Is(
"DependentObject.ID"
, dataItem.GetDataKeyValue(
"ParentObject.ID"
).ToString()));
criteria.And(ExpressionBuilder.IsNot(
"ParentObjectType"
,
"AssetGroup"
));
IList<ScopeObjectDependency> scopeObjectDependencies = scopeManager.GetScopeObjectDependencies(
out
totalRecords, criteria);
e.DetailTableView.VirtualItemCount = scopeObjectDependencies.Count();
e.DetailTableView.DataSource = scopeObjectDependencies;
}
}