I have a web in asp.net+VB+SQL DB. I have large number of inventory of items added in it. i want to print selected items in a specific format. as all the items will not come in a single A4 paper so that i can select the items to be printed and take the
signature from the in charges of the sections for records. the field in the table is as under
You could add a checkbox in the Data control to select items, then refer to the following code to print items:
Protected Sub Print(sender As Object, e As EventArgs)
Dim dt As DataTable = GetData()
Dim rows As New List(Of DataRow)()
For Each item As DataListItem In dlContacts.Items
If Not TryCast(item.FindControl("CheckBox1"), CheckBox).Checked Then
rows.Add(dt.Rows(item.ItemIndex))
End If
Next
For Each row As DataRow In rows
dt.Rows.Remove(row)
Next
dlContacts.DataSource = dt
dlContacts.DataBind()
For Each item As DataListItem In dlContacts.Items
item.FindControl("CheckBox1").Visible = False
Next
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
dlContacts.RenderControl(hw)
Dim html As String = sw.ToString().Replace("""", "'").Replace(System.Environment.NewLine, "")
Dim sb As New StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload = new function(){")
sb.Append("var printWin = window.open('', '', 'left=0")
sb.Append(",top=0,width=1000,height=600,status=0');")
sb.Append("printWin.document.write(""")
sb.Append(html)
sb.Append(""");")
sb.Append("printWin.document.close();")
sb.Append("printWin.focus();")
sb.Append("printWin.print();printWin.opener.location.href=printWin.opener
.location.href;")
sb.Append("printWin.close();};")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.[GetType](), "GridPrint", sb.ToString())
End Sub
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
297 Points
1171 Posts
Print selected data in a specific format
Dec 16, 2016 05:09 PM|Baiju EP|LINK
I have a web in asp.net+VB+SQL DB. I have large number of inventory of items added in it. i want to print selected items in a specific format. as all the items will not come in a single A4 paper so that i can select the items to be printed and take the signature from the in charges of the sections for records. the field in the table is as under
Id, Nomenclature, Qty, Regn_Number, Section
All-Star
45489 Points
7008 Posts
Microsoft
Re: Print selected data in a specific format
Dec 19, 2016 03:18 AM|Zhi Lv - MSFT|LINK
Hi Baiju EP,
You could add a checkbox in the Data control to select items, then refer to the following code to print items:
More details, see:
http://www.aspsnippets.com/Articles/Print-only-the-items-which-are-selected-using-checkbox-in-a-ASPNet-DataList-control.aspx
http://www.aspsnippets.com/Articles/Print-ASPNet-GridView-with-page-breaks-and-repeat-header-on-each-page.aspx
Also, you could print div content, please refer to this article:
http://www.aspsnippets.com/Articles/Print-DIV-content-without-opening-new-popup-window-using-JavaScript.aspx
Best regards,
Dillion