In the commanditemtemplate i have a button for exporting the grid.
However, my header row is not displayed. I am unable to figure out why my header is not visible.
Grid declaration:
<
NestedViewTemplate>
<telerik:RadGrid ID="RadGridKeyRelation" runat="server" Visible="false" AllowPaging="true"
AllowFilteringByColumn="true" OnInit="RadGridKeyRelation_Init" OnNeedDataSource="RadGridKeyRelation_NeedDataSource" OnItemDataBound="RadGridKeyRelation_ItemDataBound"
Width="950px" AutoGenerateColumns="false" OnItemCommand="RadGridKeyRelation_ItemCommand" OnItemCreated="RadGridKeyRelation_ItemCreated" EnableLinqExpressions="false" PageSize="10" HeaderStyle-BackColor="#5297b9" HeaderStyle-BorderColor="#ffffff">
<ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="false"
FileName="RelatedContactsExport">
<Pdf AllowAdd="false" AllowCopy="true" AllowModify="true" AllowPrinting="true" Author="Anonymous"
Keywords="None" PageBottomMargin="0.5in" PageLeftMargin="0.5in" PageRightMargin="0.5in" PageWidth="425mm"
PageTopMargin="0.5in" PageTitle="Grid export document" Subject="Grid Export" Title="Grid export"
PaperSize="Letter" />
</ExportSettings>
<MasterTableView TableLayout="Fixed" Name="KeyRelations" DataKeyNames="RelatedContactID, LastName, FirstName"
CommandItemDisplay="Top">
<Columns>
<telerik:GridTemplateColumn HeaderText="Name" UniqueName="KeyRelName" HeaderStyle-Width="20%"
FilterControlWidth="140px" DataField="LastName" CurrentFilterFunction="StartsWith"
ItemStyle-BackColor="#eef6f9" AutoPostBackOnFilter="true">
<ItemTemplate>
<br />
<asp:LinkButton ID="LinkButtonSpouseName" CssClass="linkButton" CommandName="ShowContact"
runat="server"><b><%# Eval("Name")%></b></asp:LinkButton>
<asp:Label ID="Label1" runat="server" CssClass="label" Visible='<%# !Convert.IsDBNull(Eval("Relationship")) %>'><br /><b>Relationship</b>: </asp:Label><%# Eval("Relationship")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Type" UniqueName="Type" HeaderStyle-Width="10%"
ItemStyle-BackColor="#eef6f9" DataField="RelationType">
<FilterTemplate>
<telerik:RadComboBox ID="RadComboBoxRelatedContacts" runat="server" AutoPostBack="true"
OnPreRender="RadComboBoxRelatedContacts_PreRender" Width="95px" OnSelectedIndexChanged="RadComboBoxRelatedContacts_SelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem Text="Family" Value="Family" />
<telerik:RadComboBoxItem Text="Business" Value="Business" />
<telerik:RadComboBoxItem Text="Personal" Value="Personal" />
<telerik:RadComboBoxItem Text="Professional" Value="Professional" />
<telerik:RadComboBoxItem Text="Colleagues" Value="Colleagues" />
</Items>
</telerik:RadComboBox>
</FilterTemplate>
<ItemTemplate>
<%
# Eval("RelationType")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Phone" UniqueName="Phone" HeaderStyle-Width="21%"
ItemStyle-BackColor="#eef6f9" AllowFiltering="false">
<ItemTemplate>
<%
# Eval("Phone")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Remarks" UniqueName="Remarks" HeaderStyle-Width="10%"
ItemStyle-BackColor="#eef6f9" FilterControlWidth="75px" DataField="Remarks" AllowFiltering="false">
<ItemTemplate>
<%
# Eval("Remarks")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemTemplate>
<asp:LinkButton ID="LinkButtonExportKeyRel" runat="server" CommandName="Export" OnClick="LinkGridRelatedContactPrint_OnClick"
CausesValidation="false" Text="Export" ForeColor="Black"></asp:LinkButton>
</CommandItemTemplate>
<PagerStyle Position="TopAndBottom" PrevPageText="Prev" NextPageText="Next" />
</MasterTableView>
</telerik:RadGrid>
.cs code for export
protected
void LinkGridRelatedContactPrint_OnClick(object sender, EventArgs e)
{
foreach (GridNestedViewItem item in RadGridContact.MasterTableView.GetItems(Telerik.Web.UI.GridItemType.NestedView))
{
RadGrid gridKeyRel = (RadGrid)item.FindControl("RadGridKeyRelation");
gridKeyRel.Rebind();
FormatGridExport(gridKeyRel);
gridKeyRel.MasterTableView.ExportToPdf();
}
}
I am also unable to put any formatting on the pdf export.
private
void FormatGridExport(RadGrid grid)
{
foreach(GridHeaderItem headerItem in grid.MasterTableView.GetItems(Telerik.Web.UI.GridItemType.Header))
{
headerItem.Style[
"font-size"] = "6pt";
headerItem.Style[
"color"] = "#ffffff";
headerItem.Style[
"background-color"] = "#003e7e";
headerItem.Style["vertical-align"] = "middle";
foreach (TableCell cell in headerItem.Cells)
{
cell.Style[
"font-family"] = "Tahoma";
cell.Style[
"text-align"] = "center";
cell.Style[
"font-weight"] = "normal";
cell.Style[
"border-color"] = "#003e7e";
}
}
foreach (Telerik.Web.UI.GridItem dataItem in grid.MasterTableView.GetItems(Telerik.Web.UI.GridItemType.Item))
{
foreach (TableCell cell in dataItem.Cells)
{
cell.Style[
"font-family"] = "Tahoma";
cell.Style[
"text-align"] = "center";
cell.Style[
"color"] = "#898a8c";
cell.Style[
"font-size"] = "5.5pt";}
}
}
What am I doing wrong here?