sandy
sandy

Reputation: 61

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

Upvotes: 5

Views: 4590

Answers (1)

PraveenVenu
PraveenVenu

Reputation: 8337

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.

Upvotes: 4

Related Questions