Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Default.aspx.cs page

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
public partial class _Default : System.Web.UI.Page
{
    ReportDocument cryRpt = new ReportDocument();
   
    protected void Page_Load(object sender, EventArgs e)
    {
                     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            cryRpt.Load(Server.MapPath("CrystalReport.rpt"));
            crConnectionInfo.ServerName = "ABC-PC";
            crConnectionInfo.DatabaseName = "am";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "sa123";
            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }
            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            crParameterDiscreteValue.Value = TextBox1.Text;
            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["emp id"];
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
            crParameterValues = crParameterFieldDefinition.CurrentValues;
            CrystalReportViewer1.ReportSource = cryRpt;
            //CrystalReportViewer1.ReuseParameterValuesOnRefresh = true; 
            CrystalReportViewer1.DataBind();
            //CrystalReportViewer1.RefreshReport();
           //CrystalReportViewer1.Visible = true;
     
      
    }
}


Default.aspx

XML
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
            ToolTip="GETTING THE INFO OF EMPLOYEE" />
        <asp:TextBox ID="TextBox1" runat="server" onload="Page_Load"></asp:TextBox>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
            AutoDataBind="true" ToolPanelView="None"
            ReuseParameterValuesOnRefresh="True" HasRefreshButton="True" />

    </div>
    </form>
</body>
</html>



This code is working fine but when I enter a value in text box then everytime it shows the similar value. If I close the project and run it again, then it shows the correct answer but when I enter the value again the second time, the crystal report shows me the previous report.

CrystalReportViewer1.RefreshReport();

is not working properly

PLEASE GIVE ME ANSWERE QUICKLY

Thanks
Posted
Updated 24-May-11 2:50am
v2

try after deleting onload="Page_Load" this.
 
Share this answer
 
cryRpt.ReportOptions.EnableSaveDataWithReport = false;
 
Share this answer
 

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