水晶报表预览

1、创建一个CrystalReport.rpt新项目,将报表格式设计好,如图:

2、创建一个XMLSchema2.xsd新项目,如图:

3.将.rpt与.xsd建立连接,点选资料库档案-会弹出一个选择.xsd文件的窗口-找到相应路径选中.xsd文件点确认即可

如点选某个按扭根据页面输入的查询条件得到的信息需产生一个报表预览出来:

该按扭事件方法为:

protected void btnSel_Click(object sender, EventArgs e)
    {
        if (tbSETACT_YM.Text == "")
        {
            Common.Common.ShowMsg(this, this.tbSETACT_YM, "庫存月結年月不能為空!");
            return;
        }
        ScriptManager.RegisterStartupScript(this.tbSETACT_YM, this.GetType(), "updateScript", "window.open('PrintRpt.aspx?setAct_YM=" + this.tbSETACT_YM.Text + "&stockName=" + this.ddlStockName.SelectedItem.Value + "','_blank');", true);//必须要跳转到另一页面才能显示出来CrystalReportViewer控件直接放在本页面显示
    }

PrintRpt.aspx页面只有一个CrystalReportViewer控件,页面执行代码:

View Code
 1 引用using CrystalDecisions.CrystalReports.Engine;命名空间
2
3 IM08RAcc acc = new IM08RAcc();
4 protected void Page_Load(object sender, EventArgs e)
5 {
6
7 }
8 protected void Page_Init(object sender, EventArgs e)
9 {
10 //取得前一页面传来的两个查询条件
11 string setAct_YM = Request["setAct_YM"].ToString();
12 string stockName = Request["stockName"].ToString();
13 //根据条件获得相应信息
14 DataTable dt = new DataTable();
15 dt = acc.getPrintDate(setAct_YM, stockName);
16
17 ReportDocument report = new ReportDocument();//创建一个rpt文件
18 report.Load(Server.MapPath("CrystalReport.rpt"));
19 report.SetDataSource(dt);将dt付给rpt
20 this.CrystalReportViewer1.ReportSource = report;//绑定
21 }

报表显示效果为:



posted @ 2012-03-06 17:39  志誠  阅读(2131)  评论(0编辑  收藏  举报