I have the following markup to create a grid with a nested view template and I cannot get the DetailTableDataBind event to fire. Could someone please review my code and walk me through the steps needed to get the detail tables to bind programmatically?
Here is my .aspx markup and code behind:
Here is my .aspx markup and code behind:
<
telerik:RadGrid
ID
=
"RadGrid"
OnItemCreated
=
"RadGrid_ItemCreated"
OnItemCommand
=
"RadGrid_ItemCommand"
OnPreRender
=
"RadGrid_PreRender"
runat
=
"server"
AllowSorting
=
"true"
AllowPaging
=
"false"
AutoGenerateColumns
=
"false"
AllowFilteringByColumn
=
"true"
OnNeedDataSource
=
"RadGrid_NeedDataSource"
OnDetailTableDataBind
=
"RadGrid_DetailTableDataBind"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
HierarchyLoadMode
=
"ServerBind"
AllowFilteringByColumn
=
"true"
ShowFooter
=
"true"
AllowPaging
=
"false"
AllowMultiColumnSorting
=
"true"
DataKeyNames
=
"UnitId"
>
<
NestedViewSettings
>
<
telerik:ParentTableRelation
>
<
telerik:GridRelationFields
MasterKeyField
=
"UnitId"
DetailKeyField
=
"UnitId"
/>
</
telerik:ParentTableRelation
>
</
NestedViewSettings
>
<
NestedViewTemplate
>
<
asp:Panel
runat
=
"server"
ID
=
"InnerContainer"
CssClass
=
"viewWrap"
Visible
=
"false"
>
<
telerik:RadTabStrip
runat
=
"server"
ID
=
"TabStip1"
MultiPageID
=
"Multipage1"
SelectedIndex
=
"0"
>
<
Tabs
>
<
telerik:RadTab
runat
=
"server"
Text
=
"Orders"
PageViewID
=
"PageView1"
>
</
telerik:RadTab
>
</
Tabs
>
</
telerik:RadTabStrip
>
<
telerik:RadMultiPage
runat
=
"server"
ID
=
"Multipage1"
SelectedIndex
=
"0"
RenderSelectedPageOnly
=
"false"
>
<
telerik:RadPageView
runat
=
"server"
ID
=
"PageView1"
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"Orders"
ShowFooter
=
"true"
AllowSorting
=
"true"
EnableLinqExpressions
=
"false"
OnDetailTableDataBind
=
"RadGrid_DetailTableDataBind"
>
<
MasterTableView
HierarchyLoadMode
=
"ServerOnDemand"
ShowHeader
=
"true"
DataKeyNames
=
"UnitId"
AutoGenerateColumns
=
"false"
AllowFilteringByColumn
=
"true"
ShowFooter
=
"true"
AllowPaging
=
"false"
AllowMultiColumnSorting
=
"true"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"UnitId"
HeaderText
=
"UnitId"
HeaderButtonType
=
"TextButton"
DataField
=
"UnitId"
UniqueName
=
"UnitId"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Date"
HeaderText
=
"Date"
HeaderButtonType
=
"TextButton"
DataField
=
"Date"
UniqueName
=
"Date"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"BillNumber"
HeaderText
=
"Bill Number"
HeaderButtonType
=
"TextButton"
DataField
=
"BillNumber"
UniqueName
=
"BillNumber"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Status"
HeaderText
=
"Status"
HeaderButtonType
=
"TextButton"
DataField
=
"Status"
UniqueName
=
"Status"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Origin"
HeaderText
=
"Origin"
HeaderButtonType
=
"TextButton"
DataField
=
"Origin"
UniqueName
=
"Origin"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Destination"
HeaderText
=
"Destination"
HeaderButtonType
=
"TextButton"
DataField
=
"Destination"
UniqueName
=
"OrDestinationigin"
>
</
telerik:GridBoundColumn
>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"XCharges"
HeaderText
=
"Acc. Charges"
SortExpression
=
"XCharges"
UniqueName
=
"XCharges"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"TotalCharge"
HeaderText
=
"Total Charges"
SortExpression
=
"TotalCharge"
UniqueName
=
"TotalCharge"
DataType
=
"System.Decimal"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
telerik:RadPageView
>
</
telerik:RadMultiPage
>
</
asp:Panel
>
</
NestedViewTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderStyle-Width
=
"10"
DataField
=
"Division"
HeaderText
=
"Division"
SortExpression
=
"Division"
UniqueName
=
"Division"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
/>
<
telerik:GridBoundColumn
DataField
=
"Subdivision"
HeaderText
=
"Subdivision"
SortExpression
=
"Subdivision"
UniqueName
=
"Subdivision"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
/>
<
telerik:GridBoundColumn
DataField
=
"UnitId"
HeaderText
=
"Unit"
SortExpression
=
"UnitId"
UniqueName
=
"UnitId"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"GrossRevenue"
HeaderText
=
"Revenue"
SortExpression
=
"GrossRevenue"
UniqueName
=
"GrossRevenue"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"TotalPay"
HeaderText
=
"Driver Pay"
SortExpression
=
"TotalPay"
UniqueName
=
"TotalPay"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"TotalFuel"
HeaderText
=
"Fuel Cost"
SortExpression
=
"TotalFuel"
UniqueName
=
"TotalFuel"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"TotalMaintenance"
HeaderText
=
"Maint. Cost"
SortExpression
=
"TotalMaintenance"
UniqueName
=
"TotalMaintenance"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"Contribution"
HeaderText
=
"Contribution"
SortExpression
=
"Contribution"
UniqueName
=
"Contribution"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Avg"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"TotalCPM"
HeaderText
=
"Total CPM"
SortExpression
=
"TotalCPM"
UniqueName
=
"TotalCPM"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Avg"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"PayCPM"
HeaderText
=
"Pay CPM"
SortExpression
=
"PayCPM"
UniqueName
=
"PayCPM"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Avg"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"FuelCPM"
HeaderText
=
"Fuel CPM"
SortExpression
=
"FuelCPM"
UniqueName
=
"FuelCPM"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Currency"
Aggregate
=
"Avg"
FooterAggregateFormatString
=
"{0:C}"
DataField
=
"MaintenanceCPM"
HeaderText
=
"Maint. CPM"
SortExpression
=
"MaintenanceCPM"
UniqueName
=
"MaintenanceCPM"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Number"
DataFormatString
=
"{0:N2}"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0:N2}"
DataField
=
"TotalMiles"
HeaderText
=
"Total Miles"
SortExpression
=
"TotalMiles"
UniqueName
=
"TotalMiles"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
<
telerik:GridNumericColumn
NumericType
=
"Number"
DataFormatString
=
"{0:N2}"
Aggregate
=
"Avg"
FooterAggregateFormatString
=
"{0:N2}"
DataField
=
"MPG"
HeaderText
=
"MPG"
SortExpression
=
"MPG"
UniqueName
=
"MPG"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
ShowFilterIcon
=
"true"
DataType
=
"System.Decimal"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
public
partial
class
UtilizationReport : System.Web.UI.Page
{
private
BTReports.Repository.UnitUtilizationRepository rep =
new
Repository.UnitUtilizationRepository();
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
RadGrid_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
if
(Cache[
"UtilzationData"
] ==
null
)
{
if
(StartDatePicker.SelectedDate.HasValue && EndDatePicker.SelectedDate.HasValue)
{
RadGrid.DataSource = rep.GetUnitUtilization(StartDatePicker.SelectedDate.Value, EndDatePicker.SelectedDate.Value);
}
}
else
{
RadGrid.DataSource = Cache[
"UtilzationData"
];
}
}
protected
void
GenerateButton_Click(
object
sender, EventArgs e)
{
Cache.Remove(
"UtilzationData"
);
Cache[
"UtilzationData"
] = rep.GetUnitUtilization(StartDatePicker.SelectedDate.Value, EndDatePicker.SelectedDate.Value);
RadGrid.DataSource = rep.GetUnitUtilization(StartDatePicker.SelectedDate.Value, EndDatePicker.SelectedDate.Value);
RadGrid.DataBind();
}
protected
void
RadGrid_DetailTableDataBind(
object
source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch
(e.DetailTableView.Name)
{
case
"Orders"
:
{
DataTable table =
new
DataTable();
table.Columns.Add(
"UnitId"
,
typeof
(
string
));
table.Columns.Add(
"Date"
,
typeof
(DateTime));
table.Columns.Add(
"BillNumber"
,
typeof
(
string
));
table.Columns.Add(
"Status"
,
typeof
(
string
));
table.Columns.Add(
"Origin"
,
typeof
(
string
));
table.Columns.Add(
"Destination"
,
typeof
(
string
));
table.Columns.Add(
"XCharge"
,
typeof
(
decimal
));
table.Columns.Add(
"TotalCharges"
,
typeof
(
decimal
));
string
UnitId = dataItem.GetDataKeyValue(
"UnitId"
).ToString();
IQueryable<UnitUtilization> data = (IQueryable<UnitUtilization>)Cache[
"UtilzationData"
];
var results = from i
in
data
where i.UnitId == UnitId
select i.Orders;
foreach
(var order
in
results)
{
foreach
(Order o
in
order)
{
table.Rows.Add(o.UnitId, o.Date, o.BillNumber, o.Status, o.Origin, o.Destination, o.XCharges, o.TotalCharges);
}
}
e.DetailTableView.DataSource = table;
break
;
}
}
}
protected
void
RadGrid_PreRender(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
//RadGrid.MasterTableView.Items[0].Expanded = true;
//RadGrid.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
}
}
protected
void
RadGrid_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item
is
GridDataItem)
{
((GridDataItem)e.Item).ChildItem.FindControl(
"InnerContainer"
).Visible =
!e.Item.Expanded;
}
}
protected
void
RadGrid_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNestedViewItem)
{
e.Item.FindControl(
"InnerContainer"
).Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
}
}
protected
void
ExportButton_Click(
object
sender, System.EventArgs e)
{
RadGrid.MasterTableView.ExportToExcel();
}
protected
void
ChartButton_Click(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid.MasterTableView.Items)
{
string
UnitId = item[
"UnitId"
].ToString();
}
}
}