locked
crystal report RRS feed

  • Question

  • User-2087114026 posted

    Hi, I need help with Crystal report, I am new with this. I just followed a tutorial online but it doesnt appear to be right.. please see codes I have.. report is not generating..

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

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    CrystalReportViewer1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    CrystalReportViewer1.Visible = true;
    ReportDocument rDoc = new ReportDocument();
    DataSet2 dset = new DataSet2(); // dataset file name
    rDoc.Load(Server.MapPath("CrystalReportCS.rpt")); // Your .rpt file path
    rDoc.SetDataSource(dset); //set dataset to the report viewer.
    CrystalReportViewer1.ReportSource = rDoc;
    }
    protected void CrystalReportViewer1_Load(object sender, EventArgs e)
    {
    ReportDocument report = new ReportDocument();
    CrystalReportViewer1.ReportSource = report;
    }
    }

    ans for the default page

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
    <p>
    <br />
    </p>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" Height="202px" ReportSourceID="CrystalReportSourceCS" ToolPanelWidth="200px" Width="1104px" OnLoad="CrystalReportViewer1_Load" />
    <CR:CrystalReportSource ID="CrystalReportSourceCS" runat="server">
    <report filename="CrystalReportCS.rpt">
    </report>
    </CR:CrystalReportSource>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" Width="115px" />
    </asp:Content>

    please help

    Sunday, September 8, 2013 12:52 PM

All replies

  • Sunday, September 8, 2013 1:01 PM
  • User-2087114026 posted

    still doesnt work...

    Sunday, September 8, 2013 1:28 PM
  • User-848409960 posted

    Is there any error in screen??

    aything that could help finding the problem?

    Sunday, September 8, 2013 1:30 PM
  • User-762086073 posted

    Step1: create new aspx page and insert the following code

    <div>
    <table width="800" style="background-color:White" border="0" cellpadding="0"
    cellspacing="0" align="center">
    <tr>
    <td style="width:25px"></td>
    <td>


    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
    DisplayGroupTree="False" oninit="CrystalReportViewer1_Init" />

    </td>
    <td></td>
    </tr>
    </table>

    <asp:Button ID="btnReport" runat="server" CausesValidation="False"
    onclick="btnReport_Click" Text="View" />

    </div>

    Step2: go to .aspx.cs page and insert the following code


    protected void Page_Load(object sender, EventArgs e)
    {

    //this.ToolkitScriptManager1.RegisterPostBackControl(this.CrystalReportViewer1);

    if (!Page.IsPostBack)
    {
    CrystalReportViewer1.ReportSource = (ReportDocument)Session["report"];

    bindReport();
    }
    else
    {
    if (Session["report"] != null)
    {
    crReportDocument = (ReportDocument)Session["report"];
    }

    }
    }


    protected void btnReport_Click(object sender, EventArgs e)
    {

    bindReport();

    }

    public void bindReport()
    {
    string reportFilePath;
    DataSet ds = new DataSet();
    try
    {
    // ScriptManager scriptManager = ScriptManager.GetCurrent(this);
    //scriptManager.RegisterPostBackControl(this.CrystalReportViewer1);
    reportFilePath = Server.MapPath("Reports//rptVouchersReport.rpt"); //this is the folder located in you root directry, change it for your conviniyance
    ds=getDataFromTable();// you call the method here to return the dataset of you data which you want to display

    if (ds.Tables[0].Rows.Count > 0)
    {
    crReportDocument.Load(reportFilePath);
    crReportDocument.SetDataSource(ds.Tables["report"]);
    Session["report"] = crReportDocument;
    CrystalReportViewer1.ReportSource = (ReportDocument)Session["report"];
    CrystalReportViewer1.DataBind();
    CrystalReportViewer1.DisplayGroupTree = false;
    CrystalReportViewer1.HasCrystalLogo = false;
    }
    else
    {
    Session["report"] = null;
    CrystalReportViewer1.ReportSource = (ReportDocument)Session["report"];

    }

    }
    catch
    {
    }


    }

    protected void Page_Init(object sender, EventArgs e)
    {
    if (Session["report"] != null)
    {
    CrystalReportViewer1.ReportSource = (ReportDocument)Session["report"];
    }
    }

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {

    }

    // reply if this sample code is helpful 

    Sunday, September 8, 2013 2:20 PM
  • User-1961616419 posted

    I suggest you to read the artcle that will explain step by step procedure to create crystal reports as per your requirement

    How to create crystal reports in visual studio 2010 using asp.net

    Monday, September 9, 2013 12:22 AM