简体   繁体   English

ASPX页面中的“打印”按钮

[英]Print Button in ASPX page

I have quick question. 我有一个快速的问题。 I have a table in ASPX page and I am trying to make my Print functionality work. 我在ASPX页中有一个表,并且正在尝试使我的打印功能正常工作。 I would like to Print particular row when a row is selected and print whole table when now row is selected. 我想在选择某行时打印特定的行,并在选择现在的行时打印整个表。 i am able to make selected row work. 我能够使选定的行工作。 but i am not able print whole table when no row is selected. 但是当没有选择任何行时,我无法打印整个表。 Is it okay to have same print button to do both functionalities or do i need to use different button. 可以使用相同的打印按钮来同时实现这两种功能还是我需要使用其他按钮? thank you 谢谢

 function PrintPage() { //var printContent = document.getElementById('<= SessionNotes.ClientID %>'); var printContent = document.getElementById('printsessionNote'); var printWindow = window.open("Selected Row", "Print Panel", 'left=50000,top=50000,width=0,height=0'); printWindow.document.write(printContent.innerHTML); printWindow.document.close(); printWindow.focus(); printWindow.print(); return false; } function Divprint(category,date,starttime,endtime,totaltime,staff,note) { $('#lblDateval').html(date); $('#lblCategoryval').html(category); $('#lblstarttimeal').html(starttime); $('#lblEndtimeal').html(endtime); $('#lblTotaltimeal').html(totaltime); $('#lblstaffphysicianal').html(staff); $('#lblnote').html(note); return false; } 
  <asp:HiddenField ID="hdn_FromID" runat="server" Value="" /> <asp:HiddenField ID="hdn_ToId" runat="server" Value="" /> <div id="printsessionNote" runat="server"> <table style="width:100%"> <tr> <td>Date</td> <td>Category</td> <td>Start Time</td> <td>End Time</td> <td>Total Time</td> <td>Staf/Physician</td> </tr> <tr> <td><label id="lblDateval"></label></td> <td><label id="lblCategoryval"></label></td> <td><label id="lblstarttimeal"></label></td> <td><label id="lblEndtimeal"></label></td> <td><label id="lblTotaltimeal"></label></td> <td><label id="lblstaffphysicianal"></label></td> </tr> <tr> <td colspan="6"> Note : <label id="lblnote"></label> </td> </tr> </table> </div> <div> <asp:Button ID="btnprintpatientlist" runat="server" Text="Print" OnClientClick=" javascript:return PrintPage();" BackColor="#FFCB05" Width="100px" Height="30" BorderWidth="0" /> <asp:Button ID="btndownloadpdf" runat="server" Text="Download" BackColor="#FFCB05" Width="100px" Height="30" BorderWidth="0" OnClick="btnExport_Click"/> </div> <p hidden="hidden" class="ses-pls">Please Select the session note(s) to print or select 'Print' to 'Print all'</p> </div> 

Just use a flag to to judge if a row is selected.When a row is selected,print the row's outerHTML.If not,print the table's outerHTML. 只需使用一个标志来判断是否选择了一行。当选择了一行时,打印行的outerHTML。否则,打印表的outerHTML。 If you want to do both,remove the first method's 'return false'. 如果您想两者都做,请删除第一种方法的“ return false”。

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

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