我想在asp.net中打印我的表单。可能吗 [英] i want to take printout of my form in asp.net. is it possible
本文介绍了我想在asp.net中打印我的表单。可能吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,
i希望在asp.net中打印我的表单,当我点击按钮打印(按钮名称)时,它应该得到我的页面的硬拷贝是否可以在asp.net中
谢谢你
sir,
i want take printout my form in asp.net, when i clicked button print(button name) it should get hardcopy of my page is it possible in asp.net
thank you
推荐答案
在这里你使用这段代码,享受:
Here you go with this code, Enjoy :
<asp:Button ID="printButton" runat="server" Text="Print" OnClientClick="javascript:window.print();" />
如何在asp.net中打印 [ ^ ]
试试这个jscript ...
Try this jscript...
<script type="text/javascript">
function printGrid() {
var gridData = document.getElementById('<%= yourForm.yourformID %>');
var windowUrl = 'Youraspxfilename.aspx';
//set print document name for gridview
var uniqueName = new Date();
var windowName = 'Print_' + uniqueName.getTime();
var prtWindow = window.open(windowUrl, windowName,
'left=100,top=100,right=100,bottom=100,width=700,height=500');
prtWindow.document.write('<html><head></head>');
prtWindow.document.write('<body style="background:none !important">');
prtWindow.document.write(gridData.outerHTML);
prtWindow.document.write('</body></html>');
prtWindow.document.close();
prtWindow.focus();
prtWindow.print();
prtWindow.close();
}
</script>
在Aspx文件中尝试此打印按钮.. 。
Try this print button in Aspx file...
<div class="form-group col-md-4">
<asp:Button ID="btnPrint" runat="server" Text="Print Data" OnClientClick="printGrid()" /> <asp:Button ID="btnPrintFromCodeBehind" runat="server" Text="Print From" OnClick="btnPrintFromCodeBehind_Click" Visible="false" />
</div>
C#代码...
C# code...
protected void btnPrintFromCodeBehind_Click(object sender, EventArgs e)
{
try
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "printGrid", "printGrid();", true);
}
catch
{
}
}
这篇关于我想在asp.net中打印我的表单。可能吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文