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

RadGrid column content on pdf export

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
leo
Top achievements
Rank 1
leo asked on 28 May 2014, 11:40 AM
Hi,

I would like to center all columns of RadGrid on the screen display as well as on pdf export of the file. How can I do that? I tried many techniques but didnt see anything happening for example:

gridview.MasterTableView.GetColumn("column").HeaderStyle.HorizontalAlign = HorizontalAlign.center

but without any success.

Any suggestions on that??? thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 May 2014, 04:16 AM
Hi Leo,

You can set the HorizontalAlign in aspx page as follows:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated">  
  <MasterTableView >
    <HeaderStyle HorizontalAlign="Center" />
      <ItemStyle HorizontalAlign="Center" />
        <AlternatingItemStyle HorizontalAlign="Center" />

To apply the style for PDF export, try the following code snippet.

C#:
bool isExport=false;
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == RadGrid.ExportToPdfCommandName)
 {
 isExport = true;
 }
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (isExport)
  {
   if (e.Item is GridHeaderItem)
     e.Item.Style["text-align"] = "middle";
 
   if (e.Item is GridDataItem)
     e.Item.Style["text-align"] = "center";
  }  
}

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