【问题标题】:ASP.Net Print GridViewASP.Net 打印网格视图
【发布时间】:2013-11-08 14:58:23
【问题描述】:

我正在开发一个 ASP.Net Web 表单应用程序。一个页面特别显示了一个 GridView,它列出了几行数据。 GridView 使用您可以在 Visual Studio 中选择的内置格式设置样式。但是,我需要创建此网页的打印友好版本,但是当我单击打印时,GridView 的样式/ css 消失了。

是否有保留作为网页查看时可见的漂亮样式/css?

感谢您的帮助。

【问题讨论】:

  • 您的意思是样式在实际打印输出中丢失,还是在您的打印友好页面上丢失?
  • 我的意思是当我点击打印并查看打印预览时样式丢失了

标签: asp.net css gridview webforms


【解决方案1】:

您将使用打印样式表:

@media print
{
    /* GridView styling here */
}

或链接到专门用于打印目的的样式表:

<!--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">

来源:CSS Print Style Sheets - Examples

【讨论】:

    【解决方案2】:

    不久前,我遇到了一个真正的问题,即 .net 网络表单坚持为 Gridviews 生成的表格添加样式、边框、间距、填充属性。

    我使用 javascript(使用 jQuery)来删除它们,如下所示:

    $(document).ready(function () {  
    $('table').filter(function (index) {  
        $(this).removeAttr("style");  
        $(this).removeAttr("rules");  
        $(this).removeAttr("border");  
        $(this).removeAttr("cellspacing");  
        $(this).removeAttr("cellpadding");  
    });  
    });  
    

    这允许我的 css(在 gridview 的“CssClass”属性中指定)完全控制。

    也许这对你的情况有一些帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      相关资源
      最近更新 更多