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

image Button disappear convert to pdf

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
baskar
Top achievements
Rank 1
baskar asked on 24 Aug 2011, 10:14 AM
hi,

when i convert a radgrid into pdf the image button disappear in the pdf file, 
help me 


here my code


<ExportSettings IgnorePaging="false" OpenInNewWindow="true">
                        <Pdf PageHeight="270mm" PageWidth="297mm" PageTitle="Master Billing Report" PageBottomMargin="20mm"
                            PageTopMargin="20mm" PageLeftMargin="20mm" PageRightMargin="20mm" />
  </ExportSettings>   





 <telerik:GridTemplateColumn HeaderText="Image" UniqueName="imgbyte">
                                <ItemTemplate>
                                 
                                <asp:ImageButton ID="asdf" Width="90px" Height="68px" Style="border: 1px solid #000000;"
                                        runat="server" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>


cs code

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExportToPdfCommandName)
            isPdfExport = true;
        }
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (isPdfExport)
                FormatGridItem(e.Item);
        }

protected void FormatGridItem(GridItem item)
        {
            item.Style["color"] = "#eeeeee";


            if (item is GridDataItem)
            {
                item.Style["vertical-align"] = "middle";
                item.Style["text-align"] = "center";
            }


            switch (item.ItemType) //Mimic RadGrid appearance for the exported PDF file
            {
                case GridItemType.Item: item.Style["background-color"] = "#4F4F4F"; break;
                case GridItemType.AlternatingItem: item.Style["background-color"] = "#494949"; break;
                case GridItemType.Header: item.Style["background-color"] = "#2B2B2B"; break;
                case GridItemType.CommandItem: item.Style["background-color"] = "#000000"; break;
            }


            if (item is GridCommandItem)
            {
                item.PrepareItemStyle(); //needed to span the image over the CommandItem cells
            }


        }



1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Aug 2011, 03:58 PM
Hello Baskar,

RadGrid will strip the buttons when exporting. You can add the missing images this way:

ItemCommand event

Copy Code
if (a.CommandName.Equals(RadGrid.ExportToPdfCommandName))
    isPdfExport = true;

ItemDataBound event
Copy Code
if (isPdfExport && a.Item is GridDataItem)
{
    GridDataItem item = a.Item as GridDataItem;
    TableCell cell = item["ColumnName"];
    string imageUrl = "img2.png";
    cell.Text = String.Format("<img src='{0}' alt='my image' />", imageUrl);
}

Kind regards,
Daniel
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
baskar
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or