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

Formating GroupByHeaders for exporting to PDF

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 28 Jan 2010, 04:13 AM

Hi guys,

I have been asked to output the RadGrid content to a PDF. I have used the following formatting code to do the formatting when the item is being created.
Note: that the Grid uses GroupBy headings (in which I am having trouble formatting)

Protected Sub RadGrid_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgResults.ItemDataBound  
        If (TypeOf e.Item Is GridDataItem OrElse TypeOf e.Item Is GridHeaderItem) Then 
 
            'to align the field left in the PDF even tho it looks ok on the webpage  
            For Each cell As TableCell In e.Item.Cells  
                cell.Style("text-align") = "left" 
            Next 
 
   
 
            Select Case e.Item.ItemType 'Mimic RadGrid appearance for the exported PDF file  
                Case GridItemType.Item  
                    e.Item.Style("background-color") = "#E8E8E8" 
                    Exit Select 
                Case GridItemType.AlternatingItem  
                    e.Item.Style("background-color") = "#FFFFFF" 
                    Exit Select 
                Case GridItemType.GroupHeader  
                    e.Item.Style("background-color") = "#000000" 
                    e.Item.Style("color") = "#FFFFFF " 
                    Exit Select 
                Case GridItemType.Header  
                    e.Item.Style("background-color") = "#000000" 
                    e.Item.Style("color") = "#FFFFFF" 
                    Exit Select 
            End Select 
        End If 
    End Sub 
 
 

 

 

Im assuming that the following code will format the groupby headings in the table however in the PDF it is in plain black text and not with a black background and white text: 

                Case GridItemType.GroupHeader
                    e.Item.Style("background-color") = "#000000"
                    e.Item.Style("color") = "#FFFFFF "
                    Exit Select

Any comments will be grateful,

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 02 Feb 2010, 03:30 PM
Hello Mike,

The problem is in the first condition - the code in the IF block will be executed for GridDataItem and GridHeaderItem only.

Please try the following modification:
Protected Sub RadGrid1_ItemCreated(ByVal source As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated
    If (TypeOf e.Item Is GridDataItem OrElse TypeOf e.Item Is GridHeaderItem) Then
        'to align the field left in the PDF even tho it looks ok on the webpage 
        For Each cell As TableCell In e.Item.Cells
            cell.Style("text-align") = "left"
            cell.Style("font-size") = "10pt"
        Next
    End If
 
    Select Case e.Item.ItemType 'Mimic RadGrid appearance for the exported PDF file 
        Case GridItemType.Item
            e.Item.Style("background-color") = "#FFFFFF"
            Exit Select
        Case GridItemType.AlternatingItem
            e.Item.Style("background-color") = "#F2F2F2"
            Exit Select
        Case GridItemType.GroupHeader
            e.Item.Style("background-color") = "#D9D9D9"
            e.Item.Style("color") = "#333333 "
            Exit Select
        Case GridItemType.Header
            e.Item.Style("background-color") = "#F3F3F3"
            e.Item.Style("color") = "#333333"
            Exit Select
    End Select
End Sub

Best regards,
Daniel
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or