Click here to Skip to main content
15,849,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a CR viewer and I have two parameter fields on the report. I have the code behind to find and get the correct parameter field values in order to populate the report. I am adding the code behind for one of the parameter fields and I am stuck. Here is my code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();
            TextBoxUser_ID.Text = Session["User_id"].ToString();
            CrystalReportViewer1.Visible = true;

            ReportDocument CrystalReport = new ReportDocument();
            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "User_id";
            paramField.Name = "Year";
            paramField.CurrentValues.Clear();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = TextBoxUser_ID.Text;
            paramDiscreteValue.Value = TextBoxYear.Text;
            paramFields.Add(paramField);
            CrystalReportViewer1.ParameterFieldInfo = paramFields;

            CrystalReport.Load(Server.MapPath("FormFTEReport50.rpt"));
            string sessiontype = TextBoxUser_ID.Text;
            string sessiontype = TextBoxYear.Text;
            CrystalReport.SetParameterValue("User_id", TextBoxUser_ID.Text);
            CrystalReport.SetParameterValue("Year", TextBoxYear.Text);

            string sessionid = TextBoxUser_ID.Text;
            CrystalReport.SetParameterValue("User_id", TextBoxUser_ID.Text);
            CrystalReportViewer1.ReportSource = CrystalReport;
            con.Close();
        }
    }
}


I ham stuck on the string sessiontype section. How can I get the report to populate with the correct data from the year and UserID?
Posted

1 solution

Why are you doing things twice ?

paramDiscreteValue.Value = TextBoxUser_ID.Text;
paramDiscreteValue.Value = TextBoxYear.Text;

paramField.Name = "User_id";
paramField.Name = "Year";

string sessiontype = TextBoxUser_ID.Text;
string sessiontype = TextBoxYear.Text;
 
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