asp.net不用CrystalReportViewer 直接打印

给页面放一个DropdownList,在PageLoad事件里添加以下代码:
 For Each iprt As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            DropDownList1.Items.Add(iprt)
   Next

放一个Button,点击事件为:
Dim reportDoc As ReportDocument = New ReportDocument()

       reportDoc.Load(Server.MapPath("CrystalReport1.rpt"))
        reportDoc.PrintOptions.PrinterName = DropDownList1.SelectedItem.Text
        reportDoc.PrintToPrinter(1, False, 0, 0)

在VS2005上测试通过。

今天发现一个好的办法,给画面拖一个CrystalReportSource空间CrystalReportSource1,拖一个sqldatasource,在sqldatasource中进行数据筛选,然后将它与CrystalReportSource绑定,执行下边几句进行打印

CrystalReportSource1.DataBind(); '取出筛选的数据
CrystalReportSource1.ReportDocument.PrinterName = DropDownList1.SelectedItem.Text
CrystalReportSource1.ReportDocument.PrintToPrinter(1, False, 0, 0)
posted @ 2006-11-29 20:11  彷徨......  阅读(1807)  评论(0编辑  收藏  举报