如何更改基于条件在RDLC报告一个文本框的文本?

问题描述 投票:0回答:1

我有一个RDLCReport。有在报告中显示像TextBox文本名为TextBox2一个All Employees Record。现在我想改变一些条件的基础上,该文本框的文本。就像当我点击然后Hired Employees按钮TextBox2的文本应改为而不是All Employees Record“聘用的员工记录”,当我在Rejected Employees按钮点击,那么TextBox2的文本应改为“被拒绝的员工记录”。下面是报告页面我发送的负载情况下的条件

 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
            }
        }
    }

这里是图片enter image description here

当第二个条件返回true,则texbox文本改为Hired Employees Record等等....

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

c# asp.net rdlc dynamic-rdlc-generation
1个回答
0
投票

我问了问这里的天夫妇之前,但我还没有得到答案。所以我一直寻找和解决我的问题。所以,我想提出一个答案,在希望,如果有人来到这里停留,然后有人从我的回答帮助。毕竟我们要互相帮助。所以一步一步。

1)我通过点击鼠标右键加到从Parameter工具箱Report Data并添加参数,并把它命名为paramHeaderenter image description here

enter image description here

enter image description here 2)我加入Textbox一个Report .rdlc Design,并Drag and Drop paramHeaderTextbox

3)然后我加入我的C#方法如下PrintReport代码。

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等..

© www.soinside.com 2019 - 2024. All rights reserved.