2017-05-30 73 views
0

有用于填充数据的网格,头位置不固定的,而印刷,

<asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="1000px" 
    Height="8000px" BorderColor="Black" BorderWidth="1px" Visible="true" BackColor="LightGray"> 
<asp:GridView ID="List" runat="server" Visible="False" OnRowDataBound="List_RowDataBound" AutoGenerateColumns="true"> 

     <HeaderStyle CssClass="gridstyleHead" /> 
     <RowStyle CssClass="gridRowstyle" /> 

</asp:GridView> 

并且存在适用于网格

.gridstyleHead { 
white-space: nowrap; 
text-align: left; 
font-family: Arial; 
font-size: 10pt; 
font-weight: lighter; 
padding-left: 3px; 
position: relative; 
top: expression(this.offsetParent.scrollTop); 
z-index: 10; 
} 

.gridRowstyle { 
white-space: nowrap; 
border-width: 1px; 
background-color: white; 
font-family: Arial; 
font-size: 9pt; 
height: 29px; 

}

的样式表我正尝试打印网格中的数据

function btnPrint_Click() { 
varfoo="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes, 
width=500,height=600,left=50,top=25"; 


    varprintdata=document.getElementById('<%=Panel1.ClientID%>').innerHTML; 
     var printWindow = window.open('', 'PRINT', foo); 
     var radioButtons = document.getElementsByName("ordrcvd"); 
     var ord = ''; 
     for (var x = 0; x < radioButtons.length; x++) { 
      if (radioButtons[x].checked) { 
       ord = radioButtons[x].value; 
      } 
     } 
     printWindow.document.write('<html><head><link rel="stylesheet" href="css/invoice.css" />'); 
     printWindow.document.write(' </head><body>'); 
     printWindow.document.write('<table>'); 
     printWindow.document.write('<tr><td style = "font-weight:bold;font-family:arial;font-size:12"> order Received' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : '); 
     printWindow.document.write('</td><td style = "font-weight:normal;font-family:arial;font-size:12">'); 
     printWindow.document.write(document.getElementById('<%= txtordRcvd.ClientID%>').value); 
     printWindow.document.write('</td></tr>'); 
     printWindow.document.write('<tr><td> </br>'); 
     printWindow.document.write('</td></tr>'); 
     printWindow.document.write(' </table>'); 
     printWindow.document.write(printContent); 
     printWindow.document.write('</body></html>'); 
     printWindow.document.close(); 
     printWindow.focus(); 

     return false; 
    } 

但问题是网格中的标题不是固定的,并且 我正在打印的网页显示的标题不是固定的。

网格中的标题不是固定的,但是当我试图打印该网格并向下滚动时,标题位置错位。

任何人都可以提出如何应用样式表是我打印网格,使头将被固定在事先

感谢,

回答

0

您需要使用打印媒体查询。我不能测试它是确定的,但我相信你想要这样的东西:

@media print { 
    .gridstyleHead { 
     top: 0; 
    } 
} 

或任何数字让你的头在正确的位置。

0

这是我的解决方案,我试过这种方式,它适合我, 之前(有问题提到)有一个面板叫panel1,数据绑定到该面板中的网格,样式表应用于表示要修复标题的网格。 现在,我拿了另一个类似于Panel1的面板,并将其命名为Panel2,但应用了样式,以便它不显示数据并将数据绑定到该面板中的网格,类似于之前的过程和样式表应用于该网格,标题为“不固定”。希望我的解释不错。

步骤我遵循:

我包括一类对现有的CSS文件除去表述“顶部:表达式(this.offsetParent.scrollTop);”从gridstyleHead

.gridstyleHeadlocal 
{ 
white-space: nowrap; 
text-align: left; 
font-family: Arial; 
font-size: 10pt; 
font-weight: lighter; 
padding-left: 3px; 
position: relative; 

z-index: 10; 
} 

,现在我又是Panel2其作用就像是Panel1为正在申请的风格为它的风格=显示:无

<asp:Panel ID="Panel2" style = "Display:none" runat="server" 
ScrollBars="Auto" Width="1000px" 
     Height="8000px" BorderColor="Black" BorderWidth="1px" 
     Visible="true" 
     BackColor="LightGray"> 
     <asp:GridView ID="Listlocal" runat="server" Visible="False" 
     OnRowDataBound="List_RowDataBound" AutoGenerateColumns="true"> 

     <HeaderStyle CssClass="gridstyleHeadlocal" /> 
     <RowStyle CssClass="gridRowstyle" /> 

</asp:GridView> 

,并使用 的document.getElementById在打印按钮功能称为是Panel2 ('<%= Panel2.ClientID%>')。innerHTML;

function btnPrint_Click() { 
varfoo="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=500,height=600,left=50,top=25"; 


    varprintdata=document.getElementById('<%=Panel2.ClientID%>').innerHTML; 
    var printWindow = window.open('', 'PRINT', foo); 
    var radioButtons = document.getElementsByName("ordrcvd"); 
    var ord = ''; 
    for (var x = 0; x < radioButtons.length; x++) { 
     if (radioButtons[x].checked) { 
      ord = radioButtons[x].value; 
     } 
    } 
    printWindow.document.write('<html><head><link rel="stylesheet" href="css/invoice.css" />'); 
    printWindow.document.write(' </head><body>'); 
    printWindow.document.write('<table>'); 
    printWindow.document.write('<tr><td style = "font-weight:bold;font-family:arial;font-size:12"> order Received' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : '); 
    printWindow.document.write('</td><td style = "font-weight:normal;font-family:arial;font-size:12">'); 
    printWindow.document.write(document.getElementById('<%= txtordRcvd.ClientID%>').value); 
    printWindow.document.write('</td></tr>'); 
    printWindow.document.write('<tr><td> </br>'); 
    printWindow.document.write('</td></tr>'); 
    printWindow.document.write(' </table>'); 
    printWindow.document.write(printContent); 
    printWindow.document.write('</body></html>'); 
    printWindow.document.close(); 
    printWindow.focus(); 

    return false; 
    }