水晶报表使用一

来源:互联网 发布:什么软件可以学好英语 编辑:程序博客网 时间:2024/04/30 17:47

 (1)

<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

 

(2)

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
            PrintMode="ActiveX" Width="600px" Height="400px" />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        </CR:CrystalReportSource>

 

(3)

        protected void Page_Load(object sender, EventArgs e)
        {
            this.DropDownList1.Items.Clear();
            foreach (string iprt in System.Drawing.Printing.PrinterSettings.InstalledPrinters)   //只能列出本地打印机
                this.DropDownList1.Items.Add(iprt);


            DataSet ds = bll.GetAllList();
            this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport3.rpt"));

            //注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
            CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);
            CrystalReportSource1.DataBind();

            //绑定到 CrystalReportViewer
            this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
            this.CrystalReportViewer1.DataBind();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            //应用打印机名称
            CrystalReportSource1.ReportDocument.PrintOptions.PrinterName = DropDownList1.SelectedItem.Text;

            // 将startPageN 和endPageN 参数设置为1。(最后两个参数)

           // 若设置为0,则 表示打印所有页。
            CrystalReportSource1.ReportDocument.PrintToPrinter(1, false, 1, 1);
        }

 

 

(4)

          // 设置打印页边距
            PageMargins margins;
            margins = CrystalReportSource1.ReportDocument.PrintOptions.PageMargins;
            margins.bottomMargin = 250;
            margins.leftMargin = 350;
            margins.rightMargin = 350;
            margins.topMargin = 450;
            CrystalReportSource1.ReportDocument.PrintOptions.ApplyPageMargins(margins);

 

 

原创粉丝点击