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
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.
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?
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(); }}Word/Excel Export (HTML-Based).
Thanks,
Shinu.
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.
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
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 = FalseProtected 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 IfEnd SubProtected 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 SubThanks,
Shinu.