Search code examples
c#-4.0report-viewer2010

How to change header background color of Dynamic Table Report of gotreportviewer programmatically


I am using gotreportviewer's Dynamic Table report to generate reports.

Here we will be populating data in the dataset and generate dynamically.

I would like to know how to change Report Column(Header) background color programmatically.


Solution

  • Please replace the below code in TableRdlGenerator.cs (line 110)

    private Rdl.StyleType CreateHeaderTableCellTextboxStyle()
            {
                Rdl.StyleType headerTableCellTextboxStyle = new Rdl.StyleType();
                headerTableCellTextboxStyle.Items = new object[]
                    {
                        "700",
                        "14pt"
                    };
                headerTableCellTextboxStyle.ItemsElementName = new Rdl.ItemsChoiceType5[]
                    {
                        Rdl.ItemsChoiceType5.FontWeight,
                        Rdl.ItemsChoiceType5.FontSize
                    };
                return headerTableCellTextboxStyle;
            }
    

    with

    private Rdl.StyleType CreateHeaderTableCellTextboxStyle()
            {
                Rdl.StyleType headerTableCellTextboxStyle = new Rdl.StyleType();
                headerTableCellTextboxStyle.Items = new object[]
                    {
                        "700",
                        "14pt",
                        Color.Black
                    };
                headerTableCellTextboxStyle.ItemsElementName = new Rdl.ItemsChoiceType5[]
                    {
                        Rdl.ItemsChoiceType5.FontWeight,
                        Rdl.ItemsChoiceType5.FontSize,
                        Rdl.ItemsChoiceType5.BackgroundColor,
                    };
                return headerTableCellTextboxStyle;
            }