Click here to Skip to main content
Licence 
First Posted 1 Aug 2006
Views 69,791
Bookmarked 57 times

How to include a header on each page when printing a DataGrid

By | 1 Aug 2006 | Article
An article on printing issues of DataGrid

No header on second page

Header is there on second page

Introduction

In many situations we might use a DataGrid for reporting purposes. If the report contains many pages we will face the problem of the header only appearing on the first page, and not printing on all pages. With a little JavaScript and CSS we can easily solve this issue.

Using the code

A DataGrid will be rendered as a table element.

If you apply the following CSS rule to THEAD elements:

tHead
{
  display : table-header-group;
}

then everything in a THEAD tag will be printed on every page. However, the DataGrid will not render a THEAD. So the above style will not work. We can add a THEAD to the table(rendered by the DataGrid) with the following JavaScript code.

function AddTHEAD(tableName)
{
   var table = document.getElementById(tableName); 
   if(table != null) 
   {
    var head = document.createElement("THEAD");
    head.style.display = "table-header-group";
    head.appendChild(table.rows[0]);
    table.insertBefore(head, table.childNodes[0]); 
   }
}

The parameter ‘tableName’ is the ID of the datagrid. Calling this function from Onload will work.

<body onload="javascript: AddTHEAD('DataGrid')">

The function create a THEAD tag and add the first row of the table (header) to it. If the header consists of more than one row you need to add the necessary rows to the created THEAD.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Abhilash Nedumpurath



United States United States

Member

I have 3 years of IT experience.
Doing : C#, ASP.NET,VB,SQL Server, Oracle
 
Currently working in Technopark, Kerala,India

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberMohammed Al-Kharouf13:29 7 Mar '10  
GeneralThank you! Pinmembershravaniraj2:51 29 Jun '09  
GeneralDatagrid and Heading printing Pinmemberprabodh1120:45 26 Aug '08  
GeneralThanks Pinmemberkhamis5:41 26 Jul '08  
Questionunable to get the upper line of the header on the second page onwards PinmemberMember 18828213:23 27 May '08  
GeneralSimple way to do that Pinmembersamir4118023:59 27 Sep '07  
GeneralRe: Simple way to do that Pinmembershravaniraj2:41 29 Jun '09  
Generalthanks Pinmemberchathuraka19:15 19 Aug '07  
GeneralRe: thanks PinmemberAbhilash Nedumpurath1:11 21 Aug '07  
Questioni am not getting the uper line of the header on page second onwards? Pinmembervsuneeldot20:00 17 Jan '07  
AnswerRe: i am not getting the uper line of the header on page second onwards? PinmemberMahendiran2:49 28 Aug '07  
Generalty so much PinmemberJohn Secada9:29 14 Sep '06  
GeneralRe: ty so much PinmemberAbhilash Nedumpurath1:11 21 Aug '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 1 Aug 2006
Article Copyright 2006 by Abhilash Nedumpurath
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid