Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?

C#
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:

ASP.NET
<%@ 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>
Posted
Updated 23-Feb-14 17:37pm
v3

1 solution

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

try CrystalReportViewer1.Databind() method after setting ReportSource
 
Share this answer
 
Comments
Computer Wiz99 23-Feb-14 23:02pm    
Hey JoCodes. I updated the code. Does it look right?
Computer Wiz99 23-Feb-14 23:10pm    
I added the code to the code I have and still nothing works. What I am trying to do is to build the report for the current user by using the users ID in the session. If the session ID is 12000 then the report should show the data just for that report.
JoCodes 23-Feb-14 23:14pm    
Now the code seems ok.Have you debugged the Session contains value?
Computer Wiz99 23-Feb-14 23:18pm    
Yes. The data on the report did not change, I am using SQL for my database. Right now I have the session ID to show in a textbox to make sure the right data is in the report.
JoCodes 23-Feb-14 23:25pm    
Whats the current behaviour now? Any error or the Report is not at all displaying?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900