Pages

Wednesday, July 13, 2011

To access crystal report control in code behind

To access crystal report control in code behind

Following 3 steps to access crystal report control & change value in codebehind
Steps:


1. Make an object of your crystal report.

    rptMyReport report = new rptMyReport();
2. Using object access control for which you want to do changes . cast control to TextObject


TextObject to =(TextObject) report.PageHeaderSection1.ReportObjects. ["textboxname"];

OR 

TextObject to = (TextObject)report.ReportDefinition.Sections["Section2"].ReportObjects["textboxname"];


3. Now using reference you can change the value of crystal report control .
          to.Text=newvalue;








1 comment:

  1. When the report is running but prompted for database password..then you can use bellow code to avoid this..

    using CrystalDecisions.CrystalReports.Engine;

    And then in the page load add the following 2 lines

    protected void Page_Load(object sender, EventArgs e)
    {

    CrystalReportSource1.ReportDocument.SetDatabaseLogon("user", "pswd","server","database name");

    CrystalReportViewer1.ReportSource = CrystalReportSource1;

    }

    ReplyDelete