I use C # with Visual Studio 2010.
I use an class Order and I have a property <OrderDetail> List. And I would use a grid to binding my class and to use the hierarchy to display also OrderDetail. But I do not know how. Can you explain to me?
Here are my classes simplified
public
class
Order
{
public
Order()
{
}
public
int
Id {
get
;
set
;}
public
List<OrderDetail> ListOrderDetail {
get
;
set
;}
}
public
class
OrderDetail
{
public
OrderDetail()
{
}
public
string
Article{
get
;
set
;}
public
int
Qte {
get
;
set
;}
public
double
Price {
get
;
set
;}
public
double
PriceHT {
get
{
return
Qte*Price;}}
}
Thank you in advance
6 Answers, 1 is accepted
There are a couple of approaches you can take for setting up a hierarchical RadGrid with the given object structure. You can use RadGrid's NeedDataSource event to bind RadGrid to the Orders collection you have. You can then use the DetailTableDataBind event to bind the detail tables to their parent Order item's child collection (ListOrderDetail) in your case:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
List<Order> orders =
new
List<Order>();
//populate orders here
RadGrid1.DataSource = orders;
}
protected
void
RadGrid1_DetailTableDataBind(
object
sende, GridDetailTableDataBindEventArgs e)
{
e.DetailTableView.DataSource = ((Order)e.DetailTableView.ParentItem.DataItem).ListOrderDetail;
}
The markup for the above example is:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Width
=
"800px"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
>
<
MasterTableView
HierarchyLoadMode
=
"ServerBind"
>
<
DetailTables
>
<
telerik:GridTableView
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>
Note the HierarchyLoadMode of the MasterTableView. It should be set to either ServerBind or Client. This setting is required, so that all your detail tables are databound when the parent items bind and you have access to the DataItem (which is the Order object in our case) of the parent item from the nested table:
e.DetailTableView.ParentItem.DataItem
If you want to use LoadOnDemand hierarchy binding, you cannot use the e.DetailTableView.ParentItem.DataItem property. You will have to retrieve the Order object of the parent item separately from your data source to bind to its child ListOrderDetail collection.
Attaching a test page to demonstrate the above approach.
Greetings,
Veli
the Telerik team


<telerik:gridtableview Name="Detail" PageSize="2">
</telerik:gridtableview>
((Order)e.DetailTableView.ParentItem.DataItem).ListOrderDetail becomes null when detail table deos the paging.
Can you please help?
Thanks!
The DataItem property of the Parent item is not persisted when paging in the details table you can use the ItemIndex property instead to extract the correct item from the datasource and bind the detail table:
var item = GetItemByIndex(e.DetailTableView.ParentItem.ItemIndex);
//method that gets the item from the the datasource by its index
e.DetailTableView.DataSource = item.ListOrderDetail;
Hope this helps.Regards,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

What is GetItemByIndex? radgrid function? can you give me more detail?
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.