打印和打印布局 [英] Print and Print Layout
本文介绍了打印和打印布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有1个文本框和3个列表框,我想从文本框和列表框打印数据.我该怎么做并打印数据并打印pagesetup和打印布局.
I have 1 text box and 3 list box, i want to print data from text box and list box.how should i do this thing and print data and print pagesetup and print layout.
推荐答案
亲爱的朋友,
尝试以下代码:-
Dear Friend,
Try out this code:-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sPrintScript As System.Text.StringBuilder = New System.Text.StringBuilder
sPrintScript.Append("<script type=''text/javascript''>").AppendLine("")
sPrintScript.Append("<!--").AppendLine("")
sPrintScript.Append("function printText(elementId)").AppendLine("")
sPrintScript.Append("{").AppendLine("")
sPrintScript.Append("var printContent = document.getElementById(elementId);").AppendLine("")
sPrintScript.Append("var windowUrl = ''about:blank'';").AppendLine("")
sPrintScript.Append("var windowName = ''Print'' + new Date().getTime();").AppendLine("")
sPrintScript.Append("var sTextToPrint = printContent.innerHTML;").AppendLine("")
sPrintScript.Append("var printWindow = window.open(windowUrl, windowName, ''left=50000,top=50000,width=0,height=0'');")
sPrintScript.AppendLine("")
sPrintScript.Append("printWindow.document.write(sTextToPrint);").AppendLine("")
sPrintScript.Append("printWindow.document.close();").AppendLine("")
sPrintScript.Append("printWindow.focus();").AppendLine("")
sPrintScript.Append("printWindow.print();").AppendLine("")
sPrintScript.Append("printWindow.close();").AppendLine("").Append("}").AppendLine("")
sPrintScript.Append("// -->").AppendLine("")
sPrintScript.Append("</script>")
If Not ClientScript.IsClientScriptBlockRegistered("printText") Then _
ClientScript.RegisterClientScriptBlock(Me.GetType(), "printText", sPrintScript.ToString)
Button1.Attributes.Add("onclick", String.Format("return printText(''{0}'');", Me.TextBox1.ClientID))
End Sub
该代码在VB中,因此您必须将其转换为C#.
http://www.daniweb.com/web-development/aspnet/threads/161217 [ ^ ]
希望这会对您有所帮助.如果可行,将其标记为您的答案
The code is in VB so you have to convert it into C#.
http://www.daniweb.com/web-development/aspnet/threads/161217[^]
Hope this will help you out. Mark this as your answer if it works
这篇关于打印和打印布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文