This is a migrated thread and some comments may be shown as answers.

[Solved] ExportToPdf - Add record count beneath title

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 22 Oct 2009, 08:38 PM
How would I go about adding the record count beneath the title of a pdf document created using the ExportToPdf functionality of RadGrid? Seems like a simple task, but haven't been able to figure it out yet. Any help would be greatly appreciated!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Oct 2009, 06:55 AM
Hi Michael,

I tried adding Literal control in CommadItemTemplate of RadGrid in order to show the numbre of records in the exported document. Here is the code that I tried  to achieve the functionality.

aspx:
 
<CommandItemTemplate> 
    <div style=" text-align: right;" id="div1"
        <asp:Literal ID="Literal1" runat="server"></asp:Literal> 
    </div> 
</CommandItemTemplate> 

C#:
 
bool pdfExport = false
protected void Button2_Click(object sender, EventArgs e) 
    pdfExport = true
    RadGrid1.ExportSettings.OpenInNewWindow = true
    RadGrid1.ExportSettings.ExportOnlyData = false
    RadGrid1.ExportSettings.IgnorePaging = true
    RadGrid1.MasterTableView.Rebind(); 
    RadGrid1.MasterTableView.ExportToPdf(); 
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    if (pdfExport) 
    { 
        GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; 
        Literal lt = (Literal)commandItem.FindControl("Literal1"); 
        string str = Convert.ToString(RadGrid1.MasterTableView.Items.Count + " Records"); 
        lt.Text = str; 
    } 

-Shinu.
0
Daniel
Telerik team
answered on 23 Oct 2009, 08:49 AM
Hello Michael,

Another approach is to insert the desired text directly in the raw html:
protected void RadGrid1_PdfExporting(object source, GridPdfExportingArgs e)
{
    string customText = "Test Test Test<p> </p>";
    e.RawHTML = e.RawHTML.Replace("<table", customText + "<table");
}

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Michael
Top achievements
Rank 1
answered on 23 Oct 2009, 01:34 PM
Thanks to both of you. Both solutions work great!
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
Michael
Top achievements
Rank 1
Share this question
or