protected void ButtonExportToPDF_Click(object sender, EventArgs e)
{
isPdfExport = true;
ConfigureExport();
RadGridFacility.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
RadGridFacility.ExportSettings.Pdf.PageWidth = Unit.Parse("356mm");
RadGridFacility.ExportSettings.Pdf.PageHeight = Unit.Parse("216mm");
RadGridFacility.MasterTableView.Rebind();
RadGridFacility.MasterTableView.ExportToPdf();
}
protected void RadGridFacility_ItemCreated(object sender, GridItemEventArgs e)
{
if (isPdfExport && (e.Item is GridHeaderItem || e.Item is GridDataItem))
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
dataItem.Style["font-size"] = "7pt";
dataItem.Style["white-space"] = "nowrap";
foreach (TableCell cell in dataItem.Cells)
{
cell.Style["white-space"] = "nowrap";
cell.Style["color"] = "red";
}
}
else
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item;
headerItem.Style["font-size"] = "7pt";
headerItem.Style["font-weight"] = "bold";
}
}
}
public void ConfigureExport()
{
RadGridFacility.ExportSettings.ExportOnlyData = true;
RadGridFacility.ExportSettings.IgnorePaging = CheckBoxIgnorePaging.Checked;
RadGridFacility.ExportSettings.OpenInNewWindow = false;
}
Also tried code below but all columns are of type GridExpandColumn even tho they are GridBoundColumns in the aspx?? GridExpandColumn does not have the DataFormatString property
protected void RadGridFacility_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
//add more column types to the conditional check if needed
if (e.Column is GridBoundColumn)
{
(e.Column as GridBoundColumn).DataFormatString = "<nobr>{0}</nobr>";
}
}
<telerik:RadGrid ID="RadGridFacility" runat="server" AllowPaging="True"
PageSize="100" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="FacilityID"
DataSourceID="EntityDataSourceFacility" GridLines="None" Skin="Vista"
onitemdatabound="RadGridFacility_ItemDataBound"
Font-Size="XX-Small"
onitemcreated="RadGridFacility_ItemCreated"
oncolumncreated="RadGridFacility_ColumnCreated" >
<PagerStyle Mode="NextPrevNumericAndAdvanced" PageButtonCount="5"
PagerTextFormat="Change page: {4} &nbsp;Displaying page {0} of {1}. Total items: {5}." AlwaysVisible="True" />
<headercontextmenu><collapseanimation
duration="200" type="OutQuint" /></headercontextmenu>
<mastertableview datakeynames="FacilityID"
datasourceid="EntityDataSourceFacility">
<norecordstemplate><div>There are no records to display</div></norecordstemplate>
<rowindicatorcolumn visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn>
<Columns>
<telerik:GridBoundColumn DataField="PermitNumber" HeaderText="Permit #"
SortExpression="PermitNumber" UniqueName="PermitNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TermNumber" HeaderText="Term"
SortExpression="TermNumber" UniqueName="TermNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Mine" HeaderText="Mine" HeaderStyle-Wrap="false"
SortExpression="Mine" UniqueName="Mine">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FTypeName" HeaderText="FType"
SortExpression="FTypeName" UniqueName="FTypeName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DistrictAbbrev" HeaderText="District"
SortExpression="DistrictAbbrev" UniqueName="DistrictAbbrev">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CountyCode" HeaderText="County"
SortExpression="CountyCode" UniqueName="CountyCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Acres" HeaderText="Acres"
SortExpression="Acres" UniqueName="Acres">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MineralCode" HeaderText="Min"
SortExpression="MineralCode" UniqueName="MineralCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TRS" HeaderText="T/R/S"
SortExpression="TRS" UniqueName="TRS">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="InitialOperation" HeaderText="Issued"
SortExpression="InitialOperation" UniqueName="InitialOperation">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TerminationDate" HeaderText="Terminate"
SortExpression="TerminationDate" UniqueName="TerminationDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PermitStatusCode" HeaderText="Status"
SortExpression="PermitStatusCode" UniqueName="PermitStatusCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AnnualReportDate" HeaderText="Annual Date"
SortExpression="AnnualReportDate" UniqueName="AnnualReportDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FSurface" HeaderText="Surface"
SortExpression="FSurface" UniqueName="FSurface">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="NonFed" HeaderText="NonFed"
SortExpression="NonFed" UniqueName="NonFed">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LOMAffected" HeaderText="LOM Affect"
SortExpression="LOMAffected" UniqueName="LOMAffected">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Released" HeaderText="Released"
SortExpression="Released" UniqueName="Released">
</telerik:GridBoundColumn>
</Columns>
</mastertableview>
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="100%" />
</ClientSettings>
<FilterMenu EnableTheming="True" Skin="Vista">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>