Formating GroupByHeaders for exporting to PDF

2 posts, 0 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Aug 2007

    Posted 27 Jan 2010 Link to this post

    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" 
                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,


  2. Daniel
    Daniel avatar
    4933 posts

    Posted 02 Feb 2010 Link to this post

    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"
        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,
    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top