简体   繁体   中英

Which a better way to print in asp.net vb.net?

I want to print a gridview and a labels in header and label in footer ( after the gridview populated ) to use CrystalReports or window.print or anything else that make my goal achived ( specialy something that easy to use )

Easiest way is to export the datagrid, download and print from Excel.

Dim dg As System.Web.UI.WebControls.DataGrid 'For example if your grid was called dg
Dim reportTitle As String = "Add A Title - Since DataGrid Doesn't Have One"
'export to excel
context.Response.Buffer = True
context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.ContentType = "application/vnd.ms-excel"
EnableViewState = True
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dg.RenderControl(hw)  '<-- built-in Method of all System.Web.UI.Control objects
Context.Response.Write("<b><center><font size=3 face=Verdana color=#0000FF>" & reportTitle & "</font></center></b>")
Context.Response.Write(tw.ToString())
Context.Response.Flush()
Context.Response.Close()
Context.Response.End()

For more info, you can check the Microsoft docs https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.control.rendercontrol

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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