
protected void myGrid_ItemDataBound(object sender, GridItemEventArgs e) { |
if (e.Item is GridGroupHeaderItem) { |
//stylize group header |
GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item; |
item.DataCell.Text = "<table><tr><td><b>Custom Group Header</b></td></tr></table>"; |
} |
} |
10 Answers, 1 is accepted

Please modify the table as suggested in the PDF export help topic:
PDF export
<
table
width
=
'200px'
><
colgroup
><
col
/></
colgroup
><
tr
><
td
><
b
>Custom Group Header</
b
></
td
></
tr
></
table
>
Kind regards,
Daniel
the Telerik team

Do you have any project or tutorial to Export Master/Detail Hierarchial html data, tables, images and etc. into single PDF file? I appreciate it.
I am using RadControls for Asp.Net Ajax 2010 release 2 and my Radgrid data Source is SQL or Access . Basically I would like to see my exported PDF file looks like a RadGrid FormTemplate. Thanks
gc_0620
This is a specific scenario that is not covered by our demos. If you provide a sample code (markup) that outlines your approach I will do my best to create a runnable project (provided that the scenario is not too complicated).
You can find some helpful tips and tricks in our PDF export help topic:
PDF export
Best regards,
Daniel
the Telerik team

Thanks for offering your help. As per your suggestion, below I am sending the complete source code.
Currently selected Hierarchial row into PDF works (attached: Current PDF Export Layout Selected Row with Child items.jpg) but my intention is to export the Currently selected Hierarchial row into PDF like RadGrid FormTemplate (attached: Desired PDF Export Layout Selected Row with Child items.jpg). That is all related child rows needs to be exported into FormTemplate format followed by parent item.
I did not include detail table Insert/Update/Delete Parameters declarations because I need help with Export to PDF not for data manipulations.
Thanks again and appreciate for your help.
Sincerely
GC_0620
______
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
id
=
"Head1"
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
</
asp:ScriptManager
>
<
telerik:RadGrid
Skin
=
"Web20"
ID
=
"RadGrid1"
ShowStatusBar
=
"True"
DataSourceID
=
"SqlDataSource1"
runat
=
"server"
AutoGenerateColumns
=
"False"
AllowPaging
=
"True"
GridLines
=
"None"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
OnPreRender
=
"RadGrid1_PreRender"
AllowAutomaticUpdates
=
"True"
EnableLinqExpressions
=
"False"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
AutoGenerateDeleteColumn
=
"True"
AutoGenerateEditColumn
=
"True"
>
<
ExportSettings
>
<
Pdf
PageTitle
=
"Rad Grid Selected Customers Export"
/>
</
ExportSettings
>
<
PagerStyle
Mode
=
"NumericPages"
></
PagerStyle
>
<
MasterTableView
DataSourceID
=
"SqlDataSource1"
Name
=
"Master"
DataKeyNames
=
"CustomerID"
CommandItemDisplay
=
"Top"
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"Orders"
DataKeyNames
=
"OrderID"
CommandItemDisplay
=
"Top"
DataSourceID
=
"SqlDataSource2"
Width
=
"100%"
runat
=
"server"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"CustomerID"
MasterKeyField
=
"CustomerID"
/>
</
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"OrderID"
HeaderText
=
"OrderID"
HeaderButtonType
=
"TextButton"
DataField
=
"OrderID"
UniqueName
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"OrderDate"
HeaderText
=
"Date Ordered"
HeaderButtonType
=
"TextButton"
DataField
=
"OrderDate"
UniqueName
=
"OrderDate"
DataFormatString
=
"{0:D}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Freight"
HeaderText
=
"Freight"
HeaderButtonType
=
"TextButton"
DataField
=
"Freight"
UniqueName
=
"Freight"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
table
id
=
"ChildTableMain"
class
=
"form-controls"
cellspacing
=
"2"
cellpadding
=
"1"
width
=
"100%"
border
=
"0"
rules
=
"none"
style
=
"border-collapse: collapse; background: #DCDCDC;"
>
<
tr
>
<
td
>
<
asp:Label
ID
=
"OrderDetailLabel"
CssClass
=
"form-edit_Update"
runat
=
"server"
Text
=
"Order details"
Font-Underline
=
"True"
></
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
table
id
=
"ChildTableDetail"
border
=
"0"
class
=
"form-controls"
width
=
"100%"
>
<
tr
>
<
td
style
=
"font-size: 11px"
>
Order ID:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtOrderID"
runat
=
"server"
Text='<%# Bind( "OrderID") %>' TabIndex="1" />
</
td
>
<
td
style
=
"font-size: 11px"
>
Date Ordered:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtOrderDate"
runat
=
"server"
Width
=
"200px"
Text='<%# Bind( "OrderDate","{0:D}") %>'
TabIndex="2" />
</
td
>
</
tr
>
<
tr
>
<
td
style
=
"font-size: 11px"
>
Freight:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtFreight"
Width
=
"300px"
runat
=
"server"
Text='<%# Bind( "Freight") %>'
TabIndex="3">
</
asp:TextBox
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
</
table
>
</
FormTemplate
>
</
EditFormSettings
>
<
SortExpressions
>
<
telerik:GridSortExpression
FieldName
=
"OrderDate"
></
telerik:GridSortExpression
>
</
SortExpressions
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to Pdf"
></
CommandItemSettings
>
<
ExpandCollapseColumn
Visible
=
"True"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"CustomerID"
HeaderText
=
"CustomerID"
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CompanyName"
HeaderText
=
"CompanyName"
DataField
=
"CompanyName"
UniqueName
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"ContactName"
HeaderText
=
"ContactName"
DataField
=
"ContactName"
UniqueName
=
"ContactName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Address"
HeaderText
=
"Address"
SortExpression
=
"Address"
UniqueName
=
"Address"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
table
id
=
"Table2"
class
=
"form-controls"
cellspacing
=
"2"
cellpadding
=
"1"
width
=
"100%"
border
=
"0"
rules
=
"none"
style
=
"border-collapse: collapse; background: #DCDCDC;"
>
<
tr
>
<
td
>
<
asp:Label
ID
=
"CustDetailLabel"
CssClass
=
"form-edit_Update"
runat
=
"server"
Text
=
"Customer details"
Font-Underline
=
"True"
></
asp:Label
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
table
id
=
"TableDetail"
border
=
"0"
class
=
"form-controls"
width
=
"100%"
>
<
tr
>
<
td
style
=
"font-size: 11px"
>
Customer Id:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtCustomer"
runat
=
"server"
Text='<%# Bind( "CustomerID") %>' TabIndex="1" />
</
td
>
<
td
style
=
"font-size: 11px"
>
Contact Name:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtContact"
runat
=
"server"
Width
=
"200px"
Text='<%# Bind( "ContactName") %>'
TabIndex="2" />
</
td
>
</
tr
>
<
tr
>
<
td
style
=
"font-size: 11px"
>
Company:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtCompany"
Width
=
"200px"
runat
=
"server"
Text='<%# Bind( "CompanyName") %>'
TabIndex="3">
</
asp:TextBox
>
</
td
>
<
td
style
=
"font-size: 11px"
>
Address:
</
td
>
<
td
>
<
asp:TextBox
ID
=
"TxtAddress"
Width
=
"300px"
runat
=
"server"
Text='<%# Bind( "Address") %>'
TabIndex="3">
</
asp:TextBox
>
</
td
>
</
tr
>
</
table
>
</
td
>
</
tr
>
<
tr
visible
=
"false"
>
<
td
align
=
"right"
colspan
=
"2"
>
<
asp:Button
ID
=
"btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</
asp:Button
>
<
asp:Button
ID
=
"btnCancel"
Text
=
"Cancel"
runat
=
"server"
CausesValidation
=
"False"
CommandName
=
"Cancel"
></
asp:Button
>
</
td
>
</
tr
>
</
table
>
</
FormTemplate
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
br
/>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Export selected items with child items"
OnClick
=
"Button1_Click"
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Address] FROM [Customers]"
runat="server" DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID"
InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [Address]) VALUES (@CustomerID, @CompanyName, @ContactName, @Address)"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [Address] = @Address WHERE [CustomerID] = @CustomerID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
DeleteParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
UpdateParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
</
InsertParameters
>
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID"
runat="server">
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"CustomerID"
SessionField
=
"CustomerID"
Type
=
"string"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
</
div
>
</
form
>
</
body
>
</
html
>
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Web.SessionState;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using Telerik.Web.UI.GridExcelBuilder;
using System.Text.RegularExpressions;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (RadGrid1.SelectedItems.Count != 0)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
if (!item.Selected)
item.Visible = false;
else
item.Expanded = true;
}
}
Configure_Selected_Row_Pdf_Export();
RadGrid1.MasterTableView.ExportToPdf();
}
public void Configure_Selected_Row_Pdf_Export()
{
//Landscape
RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("8.5in");
RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("11in");
//// 1/2 inch margins
RadGrid1.ExportSettings.Pdf.PageLeftMargin = Unit.Parse(".5in");
RadGrid1.ExportSettings.Pdf.PageRightMargin = Unit.Parse(".5in");
RadGrid1.ExportSettings.Pdf.PageTopMargin = Unit.Parse(".5in");
RadGrid1.ExportSettings.Pdf.PageBottomMargin = Unit.Parse(".5in");
foreach (GridDataItem item in RadGrid1.Items)
{
if (item.OwnerTableView.Name == "Orders")
{
GridTableView childTable = (GridTableView)item.OwnerTableView;
foreach (GridCommandItem cmditem in childTable.GetItems(GridItemType.CommandItem))
{
cmditem.Visible = false;
}
item.Style["text-align"] = "center";
item.Style["font-family"] = "Arial";
}
if (item.OwnerTableView.Name == "Master")
{
GridTableView masterTable = (GridTableView)item.OwnerTableView;
foreach (GridCommandItem mastercmditem in masterTable.GetItems(GridItemType.CommandItem))
{
mastercmditem.Visible = false;
}
item.Style["text-align"] = "center";
item.Style["font-family"] = "Arial";
item.Style["FontSize"] = "20px";
}
}
foreach (GridHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
{
headerItem.Style["font-family"] = "Arial";
headerItem.Style["color"] = "#F0F8FF";
headerItem.Style["background-color"] = " #008B8B";
}
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
}
bool isSelected;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
if (!e.Item.OwnerTableView.IsItemInserted)
{
Session["selIndex"] = e.Item.ItemIndex;
}
e.Item.Selected = true;
isSelected = true;
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!isSelected && Session["selIndex"] != null)
{
RadGrid1.MasterTableView.Items[(int)Session["selIndex"]].Selected = true;
Session["selIndex"] = null;
}
else if (!isSelected)
{
RadGrid1.MasterTableView.Items[0].Selected = true;
}
isSelected = false;
}
}
I attached a sample project based on your code. I hope it will be a good starting point for you.
Regards,
Daniel
the Telerik team

Nice work, you did it. It will help many users to export the data into PDF as Form Template format. I checked many articles in Telerik; never saw any solution like this before.
I hope in future release; Telerik implement this issue because we have some users who would like to see exported data in 8.5" x 11" , Tabular and Horizontal format as opposed to Vertical, the same as Windows drag in/drop control.
All the best to you, our Community and finally the Telerik and it's support Team.
Sincerely,
gc_0620
We are doing our best to improve the PDF export. If it happens to have issues when using this functionality, I recommend that you first check the corresponding topic where we frequently add new content (based on our clients' feedback) for the most common cases.
Kind regards,
Daniel
the Telerik team

Folks,
Currently Using Windows 10, IE 11 with VS 2017 and Progress® Telerik® UI for ASP.NET AJAX (Version 2018.1.117.45)
About almost 7 and 1/2 years ago, Daniel created a sample project (228082_gc-demo) based on my code. Refer above. Still is working. Now I have a requirement to modify it.
1) If Detail Table (GridTableView Name="Orders") has more than 3 rows, do a hard page break. i.e. (Export Master Table and Detail Table) into new page including their column headers. Please refer to attached. Example 'CustomerID' = 'AROUT'
2) Also export to PDF button does not do any thing in this Machine (i.e. using Windows 10). However I can save the file into a Local drive and open it. No Problem.
3) But this is not an issue with windows 8 and VS 2013 machine with IE 11. Files open correctly without prior saving .
4) If Daniel is still working with Progress please convey my regards to her. She is always pretty helpful to all Forum members.
Thanks for any help.
gc_0620
I've created a basic sample which is producing the required behavior. In order to place the master table row as header for each page, the approach from Grid - Export to PDF demo was followed.
Please give it a try and see if that works for you.
Kind regards,
Attila Antal
Progress Telerik