如何根据条件更改 RDLC 报告中文本框的文本?

How to change the Text of a Textbox in RDLC Reports based on Condition?

我有一份 RDLC 报告。该报告中有一个名为 TextBox2TextBox,显示的文本类似于 All Employees Record。现在我想根据某些条件更改该文本框的文本。就像当我点击 Hired Employees 按钮然后 TextBox2 的文本应该更改为 'Hired Employee Record' 而不是 All Employees Record 并且当我点击 Rejected Employees 按钮时,然后TextBox2 的文本应更改为 'Rejected Employee Record'。这是我发送的报告页面加载事件的条件

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
            {
                PrintAllEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
            {
                PrintHiredEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
            {
                PrintRejectedEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
            {
                PrintUnverifiedEmployeesMethod();
            }
            else
            {
                //SOMETHING
            }
        }
    }

这是图片

当第二个条件 returns 为真时,文本框文本变为 Hired Employees Record 等等....

我的第二个问题是,在报告中,只有第一页有 Header 文本,其余页面没有显示标题文本。如何实现?请帮助我。

几天前我在这里问了一个问题,但我没有得到答案。所以我一直在搜索并解决了我的问题。所以我想对此给出一个答案,希望如果有人被困在这里,那么有人会从我的答案中得到帮助。毕竟我们必须互相帮助。 就这样一步步来。

1) 我通过右键单击从 Report Data 工具箱添加一个 Parameter 并添加参数并将其命名为 paramHeader

2)我在Report .rdlc Design中添加了一个Textbox,在Textbox.

中添加了一个Drag and Drop paramHeader

3) 然后我在我的 PrintReport 方法中添加以下 C# 代码。

ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
        //Passing Parameter
        ReportParameterCollection reportParameters = new ReportParameterCollection();
        reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
        this.ReportViewer1.LocalReport.SetParameters(reportParameters);

这里的 ParamHeader 是我在第一步中添加的参数名称, HIRED EMPLOYEES REPORT 是我想在 TextBox 中显示的字符串值,我在第二步.

所以我的整体方法将如下所示

public void PrintHiredEmployeesMethod()
    {

        //set Processing Mode of Report as Local  
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        //set path of the Local report  
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
        //Passing Parameter
        ReportParameterCollection reportParameters = new ReportParameterCollection();
        reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
        this.ReportViewer1.LocalReport.SetParameters(reportParameters);
        //creating object of DataSet dsEmployee and filling the DataSet using SQLDataAdapter  
        DataSetAllEmployee dsemp = new DataSetAllEmployee();
        using (SqlConnection con = new SqlConnection(Base.GetConnection))
        {
            SqlCommand cmd = new SqlCommand(@"SELECT * FROM TableEmployee WHERE Status=@Status", con);
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@Status","HIRED");
            con.Open();
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            adapt.Fill(dsemp, "dtAllEmployeeRecord");
        }
        //Providing DataSource for the Report  
        ReportDataSource rds = new ReportDataSource("DataSetAllEmployee", dsemp.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        //Add ReportDataSource  
        ReportViewer1.LocalReport.DataSources.Add(rds);
    }

我的 Page_Load 活动将如下所示

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
            {
                PrintAllEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
            {
                PrintHiredEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
            {
                PrintRejectedEmployeesMethod();
            }
            else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
            {
                PrintUnverifiedEmployeesMethod();
            }
            else
            {
                //SOMETHING
            }
        }
    }

注意 我有四种不同的方法,但我正在根据需要更改 Header 部分。比如当用户想要打印 HIRED EMPLOYEES REPORT,然后 Header Section 显示 HIRED EMPLOYEES REPORT,如果用户想要生成 ALL EMPLOYEES REPORT,那么 Header Section 应该显示 ALL EMPLOYEES REPORT 等等..