Guide on how to display the header of GridView on every printed page

Is there a way to include the page title and GridView header on each printed page?

I am looking for a solution to display the page title and GridView heading on every printout.

While using page breaks to split the GridView across multiple pages, I noticed that only the first page includes the title and header. Subsequent pages do not display them.

When working with a dynamic GridView, my code utilizes AutoGenerateColumns="true".

Answer №1

Below is a guide on how to customize the appearance of your gridview for printing:

<style media="print">

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

</style>

To apply these styles, place them in the head section of your HTML document.

Next, enclose your gridview within a div element and assign it the class name MyCssClass.

Finally, implement the GridView1_RowDataBound event and include the following function call with the Gridview object as a parameter:

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";
            }
        }

Please note that this solution has been tested and confirmed to work with Internet Explorer and Firefox, but compatibility with Chrome has not been verified.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching background images with JQuery

Currently, I am attempting to modify the background image of a div element. The issue lies in the fact that I have saved the image in a variable and am unsure how to use it as it is not a direct file path. var bgImage = $('#box').find('img ...

Obtain CSS attributes for utilization in Rails variables and database operations

Whenever I click on multiple divs labeled as scale-up, I am able to acquire the css attribute. Yet, my goal is to save these imported css properties in Rails variables and store them in the database. Ultimately, what I aim for is to retrieve the Css prop ...

Tips for making a Toggle button in Angular2

I'm exploring how to utilize a Radio button as a toggle in Angular2. My goal is to capture the value of the Radio button when it changes without the need for creating a form. Any assistance would be greatly appreciated. [edit]: This is what I trie ...

What causes the inconsistency in how this code is displayed on IE7 compared to other browsers?

Why does IE7 not display the same as other browsers with this code? I have tested it on Chrome, Firefox, and others, and it works fine. But why does IE7 not display the same as other browsers? What can I do about it? <script> window.onload=function ...

Texture on plane is not displaying properly in Three.JS

Seeking assistance! I've been struggling all day to successfully load a texture onto my plane in Three.JS. Every time I attempt to add the desired link, it either fails or *poof* my plane disappears mysteriously. Please lend me your expertise with Thr ...

The absence of FormData.entries in submit is a limitation of the Vue framework

I recently created a Vue-App that consists of a simple form with just one <input name"surname"> and a <button type="submit">. The use case is to input "myname" and submit the form. However, when I initialize new FormData( ...

I am looking to initiate the animation by triggering the keyframe upon clicking a button

Is there a way to create an animation triggered by a button click instead of loading the page? Each table data cell has its own class with a unique keyframe defining the style changes over time. @-webkit-keyframes fadeIn { from { opacity:0; ...

Saving data to MongoDB using async operations in node.js with an array

My task involves manipulating a string and extracting specific values from it. Here is an example: var my_str = "Jenny [id:51], david, Pia [id:57], Aston [id:20], Raj, "; To achieve this, I am utilizing a function called convert_to_array(my_str) which sh ...

Tips for changing the <title> in an AngularJS one-page application

I am working on a single-page AngularJS application. The index.html file is structured as follows: <html ng-app="myApp" ng-controller="MyCtrl as myctrl"> <head> <link rel="stylesheet" href="my-style-sheet.css"> <title>{{ ...

When the mouse is clicked, the character fails to reach the intended destination or moves in the wrong direction on the HTML canvas

UPDATE: RESOLVED I am currently working on a game where the character moves by right-clicking. The character is meant to walk slowly, not teleport, towards the destination set by right-clicking on the canvas. However, I have encountered an issue where the ...

Troubleshooting Vue.js data binding problems

Utilizing HTML targeting with data binding <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <div class="row" v-for="test in tests"> <div class="col-12"> <router-link tag="a" :to="{ name: ...

Storing form datepicker data into MongoDB using Node.js

Having an issue with the date formatting between Angular Material 6's Datepicker and Node.js. When displaying the date in the browser, it shows as 06/20/1992, but in the console output, it appears as Sat Jun 20 1992 00:00:00 GMT+0800 (Philippine Stand ...

What is the best way to call an API and display the retrieved value in a div upon the page loading?

Seeking help to retrieve data from an API and display the response within a div tag. I know it's possible with jQuery, but I prefer a different approach. Currently, the page is loading blank. <body> <div id="OnLoad"></div& ...

Attempting to confirm the validity of my form

I have been attempting to validate my form in JSP, but unfortunately it is not working as expected. The form runs fine, however, the function 'validatemark' from my JavaScript file is not being called. Below is a snippet of my code: <%@ ...

Creating a PDF document with two side-by-side tables

Currently, I am working on dynamically generating a PDF using iTextSharp with phone book data from an SQL table. My program successfully creates a table with all the required information. However, the issue is that each page of the PDF only displays one l ...

Leveraging ng-class for selectively applying CSS3 animations based on conditions

When specific conditions are met in my controller, I apply two CSS3 animations to the DOM using ng-class. The animations (shake Y & shake X) are added based on certain criteria being satisfied. Here is a snippet of the relevant JavaScript code: $scope.sub ...

Is there a way to simulate a call to a method triggered by a Vue directive?

I am having an issue with the close() method in my Test component. It seems to only work when clicking outside of the div that the directive is applied to. How can I ensure that the method is triggered appropriately in my test? The component utilizes the v ...

BS grid malfunctioning in a non-uniform manner

When a division in the advantage grid is clicked, the card body of another division collapses. However, this does not occur in the disadvantage grid. Clicking on one section in the disadvantage grid does not collapse another section as it does in the advan ...

Chrome displaying an extJs Button image

Could it be that Chrome is evolving into the new IE in terms of CSS issues? Here is the code I have for creating ExtJS buttons within an accordion: var button = Ext.create('Ext.Button', { text: '<img src="'+resp.sellers.externa ...

Tips for compressing an image in a React application with the help of react-dropzone

I have integrated the react dropzone package into my Next JS app and I am looking to add automatic image compression feature. After receiving the images, I converted the blob/preview into a file reader. Then, I utilized the compressorjs package for compre ...