简体   繁体   English

ASP.Net打印GridView

[英]ASP.Net Print GridView

I am working on an ASP.Net Web Forms application. 我正在开发ASP.Net Web窗体应用程序。 One page in particular displays a GridView which lists several rows of data. 特别是一个页面显示一个列出几行数据的GridView。 The GridView is styled using the built in formatting which you can choose within Visual Studio. GridView使用内置格式设置样式,您可以在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. 但是,我需要创建这个网页的打印版本,但是当我点击打印时,GridView的样式/ css会消失。

Is there anyway of keeping the nice styling/ css that is visible when viewing as a webpage? 无论如何保持在作为网页查看时可见的漂亮样式/ css?

Thanks for you help. 谢谢你的帮助。

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 来源: CSS打印样式表 - 示例

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. 前一阵子我有一个真正的问题.net webforms坚持在Gridviews生成的表格中添加样式,边框,间距,填充属性。

I used javascript (using jQuery) to remove them, like this: 我使用javascript(使用jQuery)删除它们,如下所示:

$(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. 这允许我的css(在gridview的'CssClass'属性中指定)完全控制。

Perhaps this might be of some help in your case. 也许这可能对你的情况有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM