0
votes

i want that when page loads the report should display all records. Now when I want to show the filter record by datewise(group field) ie to show all records without filter else show record/s with filter.

My code is as below when I want to filter data

 protected void click(object sender, EventArgs e)
        {

            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(Server.MapPath("report.rpt"));
            cryRpt.SetDatabaseLogon("userid", "password", "server", "database");
            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value =Convert.ToDateTime( dtAppt.Text).ToShortDateString();
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["stdate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
            CrystalReportViewer1.ReportSource = cryRpt;
            Checkbox1.Checked = false;

        }

enter image description here What to write in if condition so that I can get all the records also what to pass in this below line?

crParameterDiscreteValue.Value =Convert.ToDateTime( dtAppt.Text).ToShortDateString();
2

2 Answers

3
votes

When you want to show all records add special value i.e. 01/01/1900

crParameterDiscreteValue.Value ="19000101";

In Formula

{?stdate} = '19000101' or {appointment.startdate} = {?stdate}

no need to use if else statement.

0
votes

The trick is to pass a "special value" to your parameter or create a new parameter to override.

A "special value" example would be 01/01/1900:

then in your selection criteria: {?stdate} = '19000101' or {appointment.startdate} = {?stdate}

If you go the other route creating a boolean parameter to override:

then in your selection criteria: {?override} or {appointment.startdate} = {?stdate}