Reputation: 5105
I am working on an ASP.Net Web Forms application. One page in particular displays a GridView which lists several rows of data. The GridView is styled using the built in formatting which you can choose within Visual Studio. However, I need to create a print friendly version of this webpage, but when I click print, the styling/ css of the GridView disappears.
Is there anyway of keeping the nice styling/ css that is visible when viewing as a webpage?
Thanks for you help.
Upvotes: 0
Views: 1561
Reputation: 4746
A while back I had a real problem with .net webforms insisting on adding style, border, spacing, padding attributes to the tables produced by Gridviews.
I used javascript (using jQuery) to remove them, like this:
$(document).ready(function () {
$('table').filter(function (index) {
$(this).removeAttr("style");
$(this).removeAttr("rules");
$(this).removeAttr("border");
$(this).removeAttr("cellspacing");
$(this).removeAttr("cellpadding");
});
});
This allowed my css (specified in the 'CssClass' attribute of the gridview) to take full control.
Perhaps this might be of some help in your case.
Upvotes: 1
Reputation: 20425
You would use a print stylesheet:
@media print
{
/* GridView styling here */
}
or link to a stylesheet specifically for print purposes:
<!--These styles styles are only for screens as set by the media value-->
<link rel="stylesheet" href="css/main.css" media="screen">
<!--These styles styles are only for print as set by the media value-->
<link rel="stylesheet" href="css/print.css" media="print">
Source: CSS Print Style Sheets - Examples
Upvotes: 1