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"
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With