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

Not able to set header text to bold in PDF.

5 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Radha
Top achievements
Rank 1
Radha asked on 03 Dec 2012, 01:34 PM
How to set header text to bold while exporting to PDF.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Dec 2012, 05:18 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        GridHeaderItem item = (GridHeaderItem)RadGrid2.MasterTableView.GetItems(GridItemType.Header)[0];
        foreach (TableCell cell in item.Cells)
        {
           cell.Style.Add("font-weight", "bold");
        }
     }
}

Thanks,
Shinu.
0
Radha
Top achievements
Rank 1
answered on 04 Dec 2012, 05:14 PM
Thanks for the reply.

Unfortunately it is not working if i write the foreach loop in item command.so can please suggest me other ways to set the style to column header.

Below is the code :

protected

 

void radGrid1_ItemCreated(object sender, GridItemEventArgs e)

 

{


 

if (e.Item is GridHeaderItem && isExport)

 

{

 

foreach (TableCell cell in e.Item.Cells)

 

{

cell.Style.Add(

"font-weight", "bold");

 

cell.Style.Add(

"border-width", "thin");

 

cell.Style.Add(

"font-family", "Verdana");

 

cell.Style.Add(

"border-style", "solid");

 

cell.Style.Add(

"font-size", "8pt");

 

}


}
}
0
Shinu
Top achievements
Rank 2
answered on 05 Dec 2012, 05:18 AM
Hi,

Try modifying the code as shown below.
C#:
bool isexport = false;
protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e)
{
 isexport = true;
 if (e.Item is GridHeaderItem && isexport)
 {
   foreach (TableCell cell in e.Item.Cells)
   {
      cell.Style.Add("font-weight", "bold");
      cell.Style.Add("font-family", "Verdana");
      cell.Style.Add("font-size", "8pt");
   }
 }
}

Thanks,
Shinu.
0
Radha
Top achievements
Rank 1
answered on 05 Dec 2012, 09:06 AM
Still the issue exists even if i set the isexport true.
0
Radha
Top achievements
Rank 1
answered on 06 Dec 2012, 10:05 AM
Hi shinu,

  I solved the issue to set the header text to bold.In our code  somewhere after apply font-weight to bold for each cell,we are setting the header text as

"<b>Test</b>"

 

; because of the bold tag while rendering it was not taking the style that i applied as you suggested above.
so i replaced bold tag with span as below:
"<span style='font-family:Verdana;font-weight:bold'>Test</span>"; and removed the cell style and it worked well.

Thanks for the support.
Radha

 

Tags
General Discussions
Asked by
Radha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Radha
Top achievements
Rank 1
Share this question
or