---
title: "水晶报表初体验"
author: "李科笠"
date: "2014-04-15T09:27:43Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-04-15T09:27:43Z"
id: 2046068
url: "https://likeli.iteye.com/blog/2046068"
---

安装水晶报表后如下使用；

配置rpt文件，如图

![](http://dl2.iteye.com/upload/attachment/0096/1145/915da491-8ac8-37b6-82c1-793e36e4dcb7.png)  
 

 

前台（Asp.net页面）：

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

<CR:CrystalReportViewer ID="ReTransport" runat="server" AutoDataBind="true" />
```

 

 

后台：

```
public void GetList()
        {
            ReportDocument doc = new ReportDocument();
            // rpt文件路径
            doc.Load(Server.MapPath("/Cry/CrystalInSchoolInfo.rpt"));
            ReTransport.ToolPanelView = ToolPanelViewType.None;
            Maticsoft.BLL.list.Lists pro = new Maticsoft.BLL.list.Lists();
            if (Session["CrystalData"]!=null)
            {
                //配置数据源dataset
                doc.SetDataSource((DataTable)Session["CrystalData"]);
                this.ReTransport.ReportSource = doc;
                this.ReTransport.DataBind();
            }
            else
            {
                HttpContext.Current.Response.Write("<script>alert('连接超时，请刷新！');window.location.href=document.referrer;</script>");
            }
        }
```

 

**使用注意：rpt文件配置过程中，页面长度代表一列，若拉的太长，会默认增加到下一页，导致误判为无法遍历数据的错觉**