Hi All,
I am using VS 2012 with the 2014 UI controls. We have a master page and this is in a content page. I have omitted sections with ---- to give main structure.
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
CellSpacing
=
"-1"
ShowFooter
=
"True"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
>
<
ExportSettings
FileName
=
"Safekeeping.xls"
IgnorePaging
=
"True"
ExportOnlyData
=
"true"
>
<
Excel
Format
=
"ExcelML"
/>
</
ExportSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
Name
=
"ShippingMaster"
DataKeyNames
=
"ScheduleId"
>
<
CommandItemSettings
ShowAddNewRecordButton
=
"False"
ShowExportToExcelButton
=
"True"
/>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
ShowFooter
=
"False"
AutoGenerateColumns
=
"false"
DataKeyNames
=
"SheduleId"
Name
=
"ShippingDetail"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"ScheduleId"
MasterKeyField
=
"ScheduleId"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ScheduleId"
UniqueName
=
"ScheduleId"
Display
=
"false"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"AccountNumber"
HeaderText
=
"Account Number"
UniqueName
=
"AccountNumber"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
----
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"CenterId"
DataType
=
"System.Int64"
UniqueName
=
"CenterId"
Display
=
"false"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ScheduleId"
DataType
=
"System.Int64"
UniqueName
=
"ScheduleId"
Display
=
"false"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
----
</
Columns
>
</
MasterTableView
>
<
PagerStyle
AlwaysVisible
=
"True"
/>
</
telerik:RadGrid
>
The code is as follows. The Lists are just POCOs.
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = GetShipmentDetailBySearch();
}
private List<
Shipment
> GetShipmentDetailBySearch()
{
if (ValidSearchCriteria())
{
lstShipment = shipUi.GetShipmentDetailBySearch(Int32.Parse(DropDrillYear.SelectedValue), TxtAccountNo.Text);
}
return lstShipment;
}
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem gdi = e.DetailTableView.ParentItem;
if (e.DetailTableView.Name == "ShippingDetail")
{
ShipmentUiController shipUi = new ShipmentUiController();
int drillYear = Int32.Parse(DropDrillYear.SelectedValue);
int scheduleId = Int32.Parse(gdi.GetDataKeyValue("ScheduleId").ToString());
List<
ShippingDetail
> sd = new List<
ShippingDetail
>();
sd = shipUi.GetShipmentBoxDetailByScheduleId(drillYear, scheduleId);
e.DetailTableView.DataSource = sd;
}
}
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
RadGrid1.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;
RadGrid1.MasterTableView.GetColumn("ShipmentDate").Visible = false;
....
RadGrid1.MasterTableView.DetailTables[0].GetColumn("ContentsFound").Visible = false;
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
RadGrid1.Rebind();
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();
}
}
And the results of the export are like this. The 20335 below is the schedule id that belongs with the detail table. So it is firing.
Center Cost Center Company No Associate Associate
Cedar Ridge 424 99 Alex Lifeson John Wetton
20335
But it should be
Center Cost Center Company No Associate Associate
Cedar Ridge 424 99 Alex Lifeson John Wetton
Customer Name Received
Robert Fripp true
Tom Waits false
I have tried numerous solutions from different threads here, but nothing seems to work correctly. I am really at my wits end on this one. This eventually needs to be ajaxified, but I am just trying to get the base working first. Any help would be greatly appreciated!!!