views:

6

answers:

0

Assalamoalaikum

I am having problem in generating report in visual studio 2008

Problem:

In CustomerList Report I want to pass the parameter i.e. CompanyID which is Sesson variable. I am passing but not getting the customers of the logged in company. Please see the code and help me.

Jaza milegii. :)

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Reporting;
using CrystalDecisions.Shared;

public partial class CustomerList : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
    {
  string reportPath = Server.MapPath("CustomerList.rpt");
  ReportDocument customerListReport = new ReportDocument();
  customerListReport.Load(reportPath);

  var parameterFieldDefinitions = customerListReport.DataDefinition.ParameterFields;
  var companyIDParameter = parameterFieldDefinitions["CompanyID"];
  var parameterValues = companyIDParameter.CurrentValues;
  var discreteCompanyID = new ParameterDiscreteValue{Value=Convert.ToInt16(Session["cmID"].ToString())};
  parameterValues.Add(discreteCompanyID);
  companyIDParameter.ApplyCurrentValues(parameterValues);
  CrystalReportViewer1.SelectionFormula = "{Customer.CompanyID} = {?companyID}";
  CrystalReportViewer1.ReportSource = customerListReport;
  CrystalReportViewer1.DataBind();

    }
}