Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
Posted

1 solution

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


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900