Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何根据条件更改RDLC报告中文本框的文本?_C#_Asp.net_Rdlc_Dynamic Rdlc Generation - Fatal编程技术网

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

C# 如何根据条件更改RDLC报告中文本框的文本?,c#,asp.net,rdlc,dynamic-rdlc-generation,C#,Asp.net,Rdlc,Dynamic Rdlc Generation,我有一份RDLC报告。该报告中有一个名为TextBox2的TextBox文本框,显示类似All Employees Record的文本。现在,我想根据某些条件更改该文本框的文本。就像当我点击雇佣员工按钮时,文本框2的文本应改为“雇佣员工记录”,而不是所有员工记录,当我点击拒绝员工按钮时,文本框2的文本应改为“拒绝员工记录”。以下是我发送的报告页面的加载事件的条件 protected void Page_Load(object sender, EventArgs e) {

我有一份
RDLC
报告。该报告中有一个名为
TextBox2
TextBox
文本框,显示类似
All Employees Record
的文本。现在,我想根据某些条件更改该文本框的文本。就像当我点击
雇佣员工
按钮时,
文本框2
的文本应改为“雇佣员工记录”,而不是
所有员工记录
,当我点击
拒绝员工
按钮时,
文本框2
的文本应改为“拒绝员工记录”。以下是我发送的报告页面的加载事件的条件

 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
            }
        }
    }
这是照片

当第二个条件返回true时,texbox文本变为
雇佣员工记录
,依此类推


我的第二个问题是,在报告中,只有第一页有标题文本,其余几页没有标题文本。如何做到这一点?请帮帮我。

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

1) 我通过右键单击并添加参数,从
报表数据
工具箱添加了一个
参数
,并将其命名为
paramHeader

2) 我在
Report.rdlc Design
中添加了一个
Textbox
,并将
paramHeader
拖放到
Textbox

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
是我在第一步中添加的参数名,
EMPLOYEES REPORT
是我想在第二步中添加的
文本框中显示的字符串值

所以我的整体方法是这样的

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);
    }
 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
            }
        }
    }
我的
Page\u Load
事件如下所示

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);
    }
 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
            }
        }
    }
注意我有四种不同的方法,但我会根据需要更改
标题
部分。就像当用户想要打印
雇佣员工报告
,然后
标题部分
显示
雇佣员工报告
,如果用户想要生成
所有员工报告
,那么
标题部分
应该显示
所有员工报告
,依此类推