I am using a custom class as the DataSource for a radgrid. My class has a structure like this (greatly simplified).
public
class
Batch
{
public
Batch() { }
public
int
BatchID {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
string
MiddleName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
DateTime BatchDate {
get
;
set
; }
public
List<Payment> Payments {
get
;
set
; }
}
public
class
Payment
{
public
Payment() { }
public
int
PaymentID {
get
;
set
; }
public
string
CheckNumber {
get
;
set
; }
public
decimal
Amount {
get
;
set
; }
}
My grid is defined like this.
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
mastertableview
datakeynames
=
"BatchID"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
HeaderText
=
"First Name"
UniqueName
=
"gbcFirstName"
/>
<
telerik:GridBoundColumn
DataField
=
"MiddleName"
HeaderText
=
"Middle Name"
UniqueName
=
"gbcMiddleName"
/>
<
telerik:GridBoundColumn
DataField
=
"LastName"
HeaderText
=
"Last Name"
UniqueName
=
"gbcLastName"
/>
<
telerik:GridBoundColumn
DataField
=
"BatchDate"
HeaderText
=
"Batch Date"
UniqueName
=
"gbcBatchDate"
/>
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
HierarchyLoadMode
=
"ServerBind"
Name
=
"gtvPayments"
DataKeyNames
=
"Payments.BatchID"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
MasterKeyField
=
"BatchID"
DetailKeyField
=
"Payments.BatchID"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Payments.CheckNumber"
HeaderText
=
"Check Number"
UniqueName
=
"gbcCheckNumber"
/>
<
telerik:GridNumericColumn
DataField
=
"Payments.Amount"
HeaderText
=
"Amount"
UniqueName
=
"gncAmount"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
mastertableview
>
</
telerik:RadGrid
>
I assign the datasource to the grid in the NeedDataSource event.
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
List<Batch> batch =
new
List<Batch>(1500);
RadGrid1.DataSource = batch;
}
Since each row in the master table datasource contains a list of its detail items is it possible to create a Master/Detail grid relationship directly from this or do I need to do something in the DetailTableDataBind event?
Thanks