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

export radgrid

7 Answers 226 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lisa
Top achievements
Rank 1
Lisa asked on 17 Jul 2012, 07:39 PM
1) I export radgrid to PDF fine but one column is not wide enough in PDF output. How can I increase the column size before it actually exports the data to PDF?

2) One column's values are shown as hyperlink in PDF as well as in Excel. How can I tell it to export the values as text as opposed to links when exporting the radgrid to PDF and to Excel?

Thank you.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Jul 2012, 06:02 AM
Hello Lisa,

You can change the column width in ItemCommand event and set the text of LinkButton in ExportCellFormatting event.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
  GridDataItem item = e.Cell.Parent as GridDataItem;
  if (e.FormattedColumn.UniqueName == "ColumnUniqueName")
  {
    TableCell cell = item["ColumnUniqueName"];
    LinkButton link = (LinkButton)item.FindControl("LinkButton1");
   cell.Text = link.Text;
  }
}
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
  if(e.CommandName==RadGrid.ExportToPdfCommandName)
 {
   RadGrid1.MasterTableView.GetColumn("UniqueName").HeaderStyle.Width = Unit.Pixel(300);//for changing column width.
 }
}

Thanks,
Shinu.
0
Lisa
Top achievements
Rank 1
answered on 18 Jul 2012, 04:11 PM

Hello Shinu,
Thank you for your input. Is it possible to change the font size when exporting to PDF?
I try this and it doesn't change the font size in PDF.
              radGrid1.MasterTableView.HeaderStyle.Font.Size = 1
I wonder if that is because PDF allows you to change the percentage of page display and font size is automatically adjusted accordingly.

Does any one have input for this?
2) One column's values are shown as hyperlink in PDF as well as in Excel. How can I tell it to export the values as text as opposed to links when exporting the radgrid to PDF and to Excel?

0
Shinu
Top achievements
Rank 2
answered on 19 Jul 2012, 07:53 AM
Hello,

Try the following code to change font size when exporting to pdf.
C#:
bool isExport = false;
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 isExport = true;
  if (e.Item is GridDataItem && isExport)
  {
    GridDataItem item = (GridDataItem)e.Item;
    foreach (TableCell cell in e.Item.Cells)
    {
     cell.Style["font-size"] = "20px"; //changing font size
    }
  }
}
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.ExportToPdfCommandName)
  {
   isExport = true;
    foreach (GridDataItem item in RadGrid1.Items)
    {
       LinkButton link = (LinkButton)item.FindControl("LinkButton1");
       item["ColumnUniqueName"].Text = link.Text;//changing linkbutton when exporting
    }
    RadGrid1.MasterTableView.ExportToPdf();
  }
}
Also take a look at the following help documentation.
Word/Excel Export (HTML-Based).

Thanks,
Shinu.
0
Lisa
Top achievements
Rank 1
answered on 19 Jul 2012, 08:31 PM
 use ImageButton and when the button is clicked it executes the event handler which takes System.EventArgs as one of the arguments. It doesn't take ExportCellFormattingEventArgs as an argument. So how can I make your example fit in here with the ImageButton? Thanks.
0
Shinu
Top achievements
Rank 2
answered on 20 Jul 2012, 05:00 AM
Hi,

Try handling the click event as shown below.
C#:
bool isExport = false;
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 isExport = true;
  if (e.Item is GridDataItem && isExport)
  {
    GridDataItem item = (GridDataItem)e.Item;
    foreach (TableCell cell in e.Item.Cells)
    {
     cell.Style["font-size"] = "20px"; //changing font size
    }
  }
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
   isExport = true;
    foreach (GridDataItem item in RadGrid1.Items)
    {
      LinkButton link = (LinkButton)item.FindControl("LinkButton1");
      item["UniqueName"].Text = link.Text;
   }
    RadGrid1.MasterTableView.ExportToPdf();
}

Thanks,
Shinu.
0
Lisa
Top achievements
Rank 1
answered on 24 Jul 2012, 07:57 PM

Your sample codes uses e.Item, but my code below doesn't support e.Item.

<asp:ImageButton ID="ImageButton1" ImageUrl="icon1.png" AlternateText="Export to Excel" runat="server" />

        Private Sub exportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ImageButton1.Click
            RadGrid1.MasterTableView.ExportToExcel()
        End Sub

0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2012, 05:03 AM
Hello Lisa,

You can set the font size in ItemCreated event. On checking for the bool variable, you can then export the grid in external button click.
VB:
Private isExport As Boolean = False
Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    isExport = True
    If TypeOf e.Item Is GridDataItem AndAlso isExport Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        For Each cell As TableCell In e.Item.Cells
                'changing font size
            cell.Style("font-size") = "20px"
        Next
    End If
End Sub
Protected Sub ImageButton1_Click(sender As Object, e As ImageClickEventArgs)
    isExport = True
    For Each item As GridDataItem In RadGrid1.Items
        Dim link As LinkButton = DirectCast(item.FindControl("LinkButton1"), LinkButton)
        item("UniqueName").Text = link.Text
    Next
    RadGrid1.MasterTableView.ExportToPdf()
End Sub

Thanks,
Shinu.
Tags
General Discussions
Asked by
Lisa
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Lisa
Top achievements
Rank 1
Share this question
or