Hi there,
I have been searching all over the forum, however, couldn't find out the solution to fix my similar case as follow:
Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
Parse error:
The 'body' start tag on line 674 position 6 does not match the end tag of 'td'. Line 689, position 39.
at line:
</td><td style="white-space:nowrap;">
I will paste my code below:
ASPX:
ASPX.CS
Cheers
I have been searching all over the forum, however, couldn't find out the solution to fix my similar case as follow:
Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
Parse error:
The 'body' start tag on line 674 position 6 does not match the end tag of 'td'. Line 689, position 39.
at line:
</td><td style="white-space:nowrap;">
I will paste my code below:
ASPX:
001.
<
div
id
=
"print_area"
>
002.
<
asp:ImageButton
ID
=
"DownloadCSV"
ImageUrl
=
"images/file-extension-csv-icon.png"
003.
OnClick
=
"DownloadCSV_Click"
runat
=
"server"
CssClass
=
"ImageButtons"
/>
004.
<
asp:ImageButton
ID
=
"DownloadPDF"
runat
=
"server"
OnClick
=
"DownloadPDF_Click"
ImageUrl
=
"images/file-extension-pdf-icon.png"
005.
CssClass
=
"pdfButton"
></
asp:ImageButton
>
006.
<
br
/>
007.
<
telerik:RadGrid
AutoGenerateColumns
=
"False"
ID
=
"RadGrid1"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
runat
=
"server"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnItemCreated
=
"RadGrid1_ItemCreated"
EnableLinqExpressions
=
"true"
HtmlEncode
=
"true"
OnPdfExporting
=
"RadGrid1_PdfExporting"
008.
ShowGroupPanel
=
"True"
CellSpacing
=
"-1"
GridLines
=
"Both"
Skin
=
"Office2010Silver"
Width
=
"100%"
>
009.
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
010.
<
GroupingSettings
CaseSensitive
=
"false"
/>
011.
<
ClientSettings
AllowKeyboardNavigation
=
"true"
>
012.
</
ClientSettings
>
013.
<
ExportSettings
IgnorePaging
=
"true"
OpenInNewWindow
=
"true"
>
014.
<
Pdf
PageHeight
=
"210mm"
PageWidth
=
"297mm"
DefaultFontFamily
=
"Arial Unicode MS"
PageTopMargin
=
"45mm"
015.
BorderStyle
=
"Medium"
BorderColor
=
"#666666"
PaperSize
=
"A4"
>
016.
</
Pdf
>
017.
</
ExportSettings
>
018.
<
MasterTableView
Width
=
"100%"
DataKeyNames
=
"JobID"
HierarchyLoadMode
=
"ServerOnDemand"
>
019.
<
Columns
>
020.
<
telerik:GridMaskedColumn
DataField
=
"JobID"
HeaderText
=
"JobID#"
021.
FilterControlWidth
=
"50px"
AutoPostBackOnFilter
=
"false"
CurrentFilterFunction
=
"EqualTo"
022.
FilterDelay
=
"2000"
ShowFilterIcon
=
"false"
Mask
=
"#####"
>
023.
<
ColumnValidationSettings
>
024.
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
025.
</
ColumnValidationSettings
>
026.
</
telerik:GridMaskedColumn
>
027.
<
telerik:GridBoundColumn
HeaderText
=
"Customer Ref No"
DataField
=
"JobCustomerRefNo"
UniqueName
=
"JobCustomerRefNo"
028.
SortExpression
=
"JobCustomerRefNo"
HeaderStyle-Width
=
"180px"
FilterControlAltText
=
"Filter JobCustomerRefNo column"
>
029.
<
ColumnValidationSettings
>
030.
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
031.
</
ColumnValidationSettings
>
032.
033.
</
telerik:GridBoundColumn
>
034.
<
telerik:GridBoundColumn
DataField
=
"JobTitle"
FilterControlAltText
=
"Filter JobTitle column"
HeaderText
=
"Job Title"
SortExpression
=
"JobTitle"
UniqueName
=
"JobTitle"
>
035.
<
ColumnValidationSettings
>
036.
<
ModelErrorMessage
Text
=
""
/>
037.
</
ColumnValidationSettings
>
038.
</
telerik:GridBoundColumn
>
039.
<
telerik:GridDateTimeColumn
DataField
=
"JobBookedDate"
PickerType
=
"DatePicker"
EnableTimeIndependentFiltering
=
"true"
040.
DataFormatString
=
"{0:dd/MM/yyyy HH:mm }"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter JobBookedDate column"
HeaderText
=
"Job Booked Date"
SortExpression
=
"JobBookedDate"
UniqueName
=
"JobBookedDate"
>
041.
<
ColumnValidationSettings
>
042.
<
ModelErrorMessage
Text
=
""
/>
043.
</
ColumnValidationSettings
>
044.
</
telerik:GridDateTimeColumn
>
045.
<
telerik:GridBoundColumn
DataField
=
"JobAddress1"
FilterControlAltText
=
"Filter JobAddress1 column"
HeaderText
=
"Address"
SortExpression
=
"JobAddress1"
UniqueName
=
"JobAddress1"
>
046.
<
ColumnValidationSettings
>
047.
<
ModelErrorMessage
Text
=
""
/>
048.
</
ColumnValidationSettings
>
049.
</
telerik:GridBoundColumn
>
050.
<
telerik:GridBoundColumn
DataField
=
"JobSuburb"
FilterControlAltText
=
"Filter JobSuburb column"
HeaderText
=
"Suburb"
SortExpression
=
"JobSuburb"
UniqueName
=
"JobSuburb"
>
051.
<
ColumnValidationSettings
>
052.
<
ModelErrorMessage
Text
=
""
/>
053.
</
ColumnValidationSettings
>
054.
</
telerik:GridBoundColumn
>
055.
<
telerik:GridBoundColumn
DataField
=
"JobPostCode"
FilterControlAltText
=
"Filter JobPostCode column"
HeaderText
=
"PostCode"
SortExpression
=
"JobPostCode"
UniqueName
=
"JobPostCode"
>
056.
<
ColumnValidationSettings
>
057.
<
ModelErrorMessage
Text
=
""
/>
058.
</
ColumnValidationSettings
>
059.
</
telerik:GridBoundColumn
>
060.
<
telerik:GridBoundColumn
DataField
=
"JobState"
FilterControlAltText
=
"Filter JobState column"
HeaderText
=
"State"
SortExpression
=
"JobState"
UniqueName
=
"JobState"
>
061.
<
ColumnValidationSettings
>
062.
<
ModelErrorMessage
Text
=
""
/>
063.
</
ColumnValidationSettings
>
064.
</
telerik:GridBoundColumn
>
065.
<
telerik:GridTemplateColumn
DataField
=
"JobStatusID"
HeaderText
=
"Status Type"
UniqueName
=
"JobStatusID"
066.
HeaderStyle-Width
=
"200px"
SortExpression
=
"JobStatusID"
>
067.
<
FilterTemplate
>
068.
<
telerik:RadComboBox
ID
=
"comboJobStatus"
DataTextField
=
"JobStatusName"
069.
DataValueField
=
"JobStatusID"
Height
=
"100px"
AppendDataBoundItems
=
"true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("JobStatusID").CurrentFilterValue %>'
070.
runat="server" OnClientSelectedIndexChanged="JobStatusIndexChanged">
071.
<
Items
>
072.
<
telerik:RadComboBoxItem
Text
=
"All"
/>
073.
</
Items
>
074.
</
telerik:RadComboBox
>
075.
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock3"
runat
=
"server"
>
076.
<
script
type
=
"text/javascript"
>
077.
function JobStatusIndexChanged(sender, args) {
078.
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
079.
tableView.filter("JobStatusID", args.get_item().get_value(), "EqualTo");
080.
}
081.
</
script
>
082.
</
telerik:RadScriptBlock
>
083.
</
FilterTemplate
>
084.
<
ItemTemplate
>
085.
<%# Eval("JobStatus") %>
086.
</
ItemTemplate
>
087.
</
telerik:GridTemplateColumn
>
088.
<
telerik:GridTemplateColumn
DataField
=
"ClientID"
HeaderText
=
"Client"
UniqueName
=
"ClientID"
089.
HeaderStyle-Width
=
"200px"
SortExpression
=
"ClientID"
>
090.
<
FilterTemplate
>
091.
<
telerik:RadComboBox
ID
=
"comboClient"
DataTextField
=
"ClientName"
092.
DataValueField
=
"ClientID"
Height
=
"100px"
AppendDataBoundItems
=
"true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ClientID").CurrentFilterValue %>'
093.
runat="server" OnClientSelectedIndexChanged="ClientIndexChanged">
094.
<
Items
>
095.
<
telerik:RadComboBoxItem
Text
=
"All"
/>
096.
</
Items
>
097.
</
telerik:RadComboBox
>
098.
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock2"
runat
=
"server"
>
099.
<
script
type
=
"text/javascript"
>
100.
function ClientIndexChanged(sender, args) {
101.
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
102.
tableView.filter("ClientID", args.get_item().get_value(), "EqualTo");
103.
}
104.
</
script
>
105.
</
telerik:RadScriptBlock
>
106.
</
FilterTemplate
>
107.
<
ItemTemplate
>
108.
<%# Eval("Client") %>
109.
</
ItemTemplate
>
110.
</
telerik:GridTemplateColumn
>
111.
<
telerik:GridTemplateColumn
DataField
=
"AssignedStaffID"
HeaderText
=
"Staff"
UniqueName
=
"AssignedStaffID"
112.
HeaderStyle-Width
=
"200px"
SortExpression
=
"AssignedStaffID"
>
113.
<
FilterTemplate
>
114.
<
telerik:RadComboBox
ID
=
"comboStaff"
DataTextField
=
"StaffName"
115.
DataValueField
=
"StaffID"
Height
=
"100px"
AppendDataBoundItems
=
"true"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("AssignedStaffID").CurrentFilterValue %>'
116.
runat="server" OnClientSelectedIndexChanged="StaffIndexChanged">
117.
<
Items
>
118.
<
telerik:RadComboBoxItem
Text
=
"All"
/>
119.
</
Items
>
120.
</
telerik:RadComboBox
>
121.
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
122.
<
script
type
=
"text/javascript"
>
123.
function StaffIndexChanged(sender, args) {
124.
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
125.
tableView.filter("AssignedStaffID", args.get_item().get_value(), "EqualTo");
126.
}
127.
</
script
>
128.
</
telerik:RadScriptBlock
>
129.
</
FilterTemplate
>
130.
<
ItemTemplate
>
131.
<%# Eval("AssignedStaff") %>
132.
</
ItemTemplate
>
133.
</
telerik:GridTemplateColumn
>
134.
</
Columns
>
135.
<
NestedViewTemplate
>
136.
<
asp:Panel
runat
=
"server"
ID
=
"InnerContainer"
CssClass
=
"viewWrap"
Visible
=
"false"
>
137.
<
telerik:RadMultiPage
runat
=
"server"
ID
=
"Multipage1"
SelectedIndex
=
"0"
RenderSelectedPageOnly
=
"false"
>
138.
<
telerik:RadPageView
runat
=
"server"
ID
=
"PageView1"
>
139.
<
telerik:RadGrid
runat
=
"server"
ID
=
"JobStatusGrid"
>
140.
<
MasterTableView
ShowHeader
=
"true"
AutoGenerateColumns
=
"False"
AllowPaging
=
"true"
141.
DataKeyNames
=
"JobStatusHistoryID"
PageSize
=
"7"
HierarchyLoadMode
=
"ServerOnDemand"
>
142.
<
Columns
>
143.
<
telerik:GridBoundColumn
HeaderText
=
"Status Type"
HeaderButtonType
=
"TextButton"
144.
DataField
=
"JobStatus"
UniqueName
=
"JobStatusID"
>
145.
</
telerik:GridBoundColumn
>
146.
<
telerik:GridBoundColumn
HeaderText
=
"Created By"
HeaderButtonType
=
"TextButton"
147.
DataField
=
"CreatedBy"
UniqueName
=
"CreatedBy"
>
148.
</
telerik:GridBoundColumn
>
149.
<
telerik:GridBoundColumn
HeaderText
=
"Created On"
HeaderButtonType
=
"TextButton"
150.
DataField
=
"CreatedOn"
UniqueName
=
"CreatedOn"
>
151.
</
telerik:GridBoundColumn
>
152.
</
Columns
>
153.
</
MasterTableView
>
154.
</
telerik:RadGrid
>
155.
</
telerik:RadPageView
>
156.
</
telerik:RadMultiPage
>
157.
</
asp:Panel
>
158.
</
NestedViewTemplate
>
159.
</
MasterTableView
>
160.
<
ClientSettings
AllowDragToGroup
=
"true"
>
161.
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
/>
162.
</
ClientSettings
>
163.
</
telerik:RadGrid
>
164.
</
div
>
ASPX.CS
01.
protected
void
DownloadPDF_Click(
object
sender, System.EventArgs e)
02.
{
03.
isPdfExport =
true
;
04.
RadGrid Grid1 = (RadGrid)Page.Master.FindControl(
"MainContent"
).FindControl(
"RadGrid1"
);
05.
Grid1.ExportSettings.Pdf.AllowPrinting =
true
;
06.
Grid1.ExportSettings.Pdf.AllowModify =
true
;
07.
Grid1.ExportSettings.Pdf.AllowCopy =
true
;
08.
Grid1.ExportSettings.Pdf.AllowAdd =
true
;
09.
Grid1.ExportSettings.Pdf.DefaultFontFamily =
"Helvetica"
;
10.
Grid1.ExportSettings.Pdf.PageLeftMargin =
new
Unit(2, UnitType.Mm);
11.
Grid1.ExportSettings.Pdf.PageRightMargin =
new
Unit(2, UnitType.Mm);
12.
Grid1.ExportSettings.Pdf.PageHeaderMargin =
new
Unit(0, UnitType.Mm);
13.
Grid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
14.
Grid1.ExportSettings.Pdf.PageHeight = Unit.Parse(
"210mm"
);
15.
Grid1.ExportSettings.Pdf.PageWidth = Unit.Parse(
"420mm"
);
16.
17.
foreach
(GridColumn col
in
RadGrid1.MasterTableView.RenderColumns)
18.
{
19.
if
(col.UniqueName !=
"MiddleInitial"
)
20.
{
21.
col.HeaderStyle.Width = Unit.Pixel(50);
22.
}
23.
}
24.
Grid1.MasterTableView.ExportToPdf();
25.
}
01.
protected
void
RadGrid1_PdfExporting(
object
sender, GridPdfExportingArgs e)
02.
{
03.
StringBuilder customHTML =
new
StringBuilder();
04.
customHTML.Append(
"<p style='color: red; font-weight: bold; font-size: 10pt;'>Title Page</p>"
);
05.
customHTML.Append(
"<table style='font-family:Helvetica;font-size:9pt;width:500px;'>"
);
06.
customHTML.Append(
"<tr><td>Customer: aaa 1</td><td>Date: bbbb 2</td></tr>"
);
07.
customHTML.Append(
"<tr><td>Address: aaa 1</td><td>Email: bbbb 2 </td></tr>"
);
08.
customHTML.Append(
"<tr><td>City: aaa 1</td><td>Phone: bbbb 2 </td></tr>"
);
09.
customHTML.Append(
"<tr><td>State: aaa 1</td><td>Zip: bbbb 2 </td></tr>"
);
10.
customHTML.Append(
"</table>"
);
11.
e.RawHTML = customHTML + e.RawHTML;
12.
}
Cheers