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