用于构建Crystal Report的代码 [英] Code to build Crystal Report

查看:45
本文介绍了用于构建Crystal Report的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我在page_load中有一个代码,它应该使用文本框中的会话ID来构建水晶报表。有人能告诉我为什么它不起作用?我做错了什么?



 使用系统; 
使用 System.Collections.Generic;
使用 System.Collections;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用 CrystalDecisions.Web;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Web.UI.WebControls;
使用 CrystalDecisions.CrystalReports.Engine;
使用 CrystalDecisions.Shared;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Xml.Linq;
使用 System.Web.SessionState;


命名空间 SACSCOCLogin1._1
{
public partial class ReportA:System.Web.UI.Page
{
受保护 void Page_Load( object sender ,EventArgs e)
{
TextBoxINST_ID.Text = Session [ inst_id ]的ToString();
CrystalReportViewer1.Visible = true ;

ReportDocument CrystalReport = new ReportDocument();
CrystalReport.Load(Server.MapPath( 〜/ Reports / ReportA.rpt) );
CrystalReport.SetDatabaseLogon
Admin master22 @ SQL Hot);
CrystalReportViewer1.ReportSource = CrystalReport;
CrystalReportViewer1.DataBind();
}
}
}





这是标记代码:



 <%@     Page    语言  =  C#    AutoEventWireup   =  true    CodeBehind   =  ReportA.aspx.cs   继承  =  SACSCOCLogin1._1.ReportA   %>  

<%@ 注册 assembly = CrystalDecisions.Web,Version = 13.0.2000.0,Culture = neutral,PublicKeyToken = 692fbea5521e1304 命名空间 = CrystalDecisions.Web tagprefix = CR %>

< !DOCTYPE html PUBLIC - // W3C / / DTD XHTML < span class =code-attribute> 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > < / title > ;
< / head >
< body >
< 表格 id = form1 runat = server >
< div >

< asp:TextBox ID = TextBoxINST_ID runat = server > < / asp:TextBox >

< / div >
< CR:CrystalReportViewer ID = CrystalReportViewer1 runat = server

< span class =code-attribute> AutoDataBind = True DisplayToolbar = False EnableDatabaseLogonPrompt = False

GroupTreeImagesFolderUrl = HasDrilldownTabs = False

< span class =code-attribute> HasToggleGroupTreeButton = False HasToggleParameterPanelButton = 错误

< span class =code-attribute> 高度 = 1142px ReportSourceID = < span class =code-keyword> CrystalReportSource1 ToolbarImagesFolderUrl =

ToolPanelView = ToolPanelWidth = 200px 宽度 < span class =code-keyword> = 868px / >
< CR:CrystalReportSource ID = CrystalReportSource1 runat = 服务器 >
< 报告 FileName = Reports\Report1.rpt >
< / Report > ;
< / CR:CrystalReportSource >
< / form >
< / body >
< / html >

解决方案

我想您忘记为Crystal Report添加数据绑定方法



设置ReportSource后尝试 CrystalReportViewer1.Databind()方法

Hello. I have a code in page_load that should build the crystal report by using the session ID that is in the textbox. Can someone tell me why is it not working? What did I do wrong?

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;


namespace SACSCOCLogin1._1
{
    public partial class ReportA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            CrystalReportViewer1.Visible = true;

            ReportDocument CrystalReport = new ReportDocument();
            CrystalReport.Load(Server.MapPath("~/Reports/ReportA.rpt"));
            CrystalReport.SetDatabaseLogon
            ("Admin", "master22", @"SQL", "Hot");
            CrystalReportViewer1.ReportSource = CrystalReport;
            CrystalReportViewer1.DataBind();
         }
    }
}



Here is the mark up code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportA.aspx.cs" Inherits="SACSCOCLogin1._1.ReportA" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:TextBox ID="TextBoxINST_ID" runat="server"></asp:TextBox>
    
    </div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" 

        AutoDataBind="True" DisplayToolbar="False" EnableDatabaseLogonPrompt="False" 

        GroupTreeImagesFolderUrl="" HasDrilldownTabs="False" 

        HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" 

        Height="1142px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" 

        ToolPanelView="None" ToolPanelWidth="200px" Width="868px" />
    <CR:CrystalReportSource ID="CrystalReportSource1"  runat="server">
        <Report FileName="Reports\Report1.rpt">
        </Report>
    </CR:CrystalReportSource>
    </form>
</body>
</html>

解决方案

I think you have forgot to add the Databind Method for the Crystal Report

try CrystalReportViewer1.Databind() method after setting ReportSource


这篇关于用于构建Crystal Report的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆