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

Right Justify on PDF export not happening.

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 10 Nov 2008, 08:34 PM
Hello,

I am having a hard time getting text alignment to work for text in ItemTemplates on PDF export.  ven straight text does not work.

I have tried in style attributes (tried both text-align and horizontal-align), ItemStyle elements attributes, and even in the OnItemCreated event.  All to no avail.  Text remains left justified.

Please help!
Thanks,
Michael

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Nov 2008, 06:15 AM
Hello Michael,

Try out the following code to get the text in cells of a grid aligned to the right.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="True" AllowPaging="true" PageSize="5" OnItemCommand="RadGrid2_ItemCommand" OnItemCreated="RadGrid2_ItemCreated"
  <MasterTableView DataSourceID="SqlDataSource1" CommandItemDisplay="Top"
    <CommandItemTemplate > 
         <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Export" CommandName="ExportToPdf" />             
    </CommandItemTemplate> 
     .... 

cs:
 bool isPdfExport = false
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == RadGrid.ExportToPdfCommandName) 
        { 
            isPdfExport = true
            RadGrid1.ExportSettings.IgnorePaging = true
            RadGrid1.ExportSettings.OpenInNewWindow = true
        } 
    } 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (isPdfExport && e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item;           
            foreach (TableCell cell in dataItem.Cells) 
            { 
                cell.Style["text-align"] = "right";                 
                cell.Style["font-size"] = "12pt"; 
                cell.Style["color"] = "red"; 
            } 
        } 
    } 

For more information on this feature,you can refer to this link.

Thanks
Princy.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or