我想打印一个网格视图,在页眉中打印标签,在页脚中打印标签(在填充网格视图之后(使用CrystalReports或window.print或者任何其他能让我实现目标的东西(特别是易于使用的东西(
最简单的方法是导出数据网格,从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()
有关详细信息,您可以查看Microsoft文档https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.rendercontrol