Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print header of GridView on each print page

How do I print the page title and the header of a GridView on each print page?

I want to add page title and GridView heading on each page.

I used page break to break the GridView into multiple pages, but only the first page comes with title and all other are without header and title page.

For a dynamic GridView, my code uses AutoGenerateColumns="true".

like image 485
sandy Avatar asked Oct 08 '22 15:10

sandy


1 Answers

Put the below in the head

<style media="print">

                .MyCssClass thead
                {
                    display: table-header-group;
                }

</style>

Now put your gridview in a div and give the div the class name MyCssClass

Now add the GridView1_RowDataBound event and in that event call the below function passing the Gridview object.

private void MakeGridViewPrinterFriendly(GridView gridView)
        {
            if (gridView.Rows.Count > 0)
            {
                gridView.UseAccessibleHeader = true;
                gridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                //gridView.HeaderRow.Style["display"] = "table-header-group";
            }
        }

this works with IE and FF. not tested in Chrome.

like image 184
PraveenVenu Avatar answered Oct 12 '22 10:10

PraveenVenu